Skip to content

Commit

Permalink
Use Laravel Pint as code style fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Oct 5, 2023
1 parent 5b682a0 commit 8772cc4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 102 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
},
"require-dev": {
"orchestra/testbench": "^7.0 || ^8.0",
"symplify/easy-coding-standard": "^11.1",
"phpunit/phpunit": "^9.6"
"phpunit/phpunit": "^9.6",
"laravel/pint": "^1.13"
},
"autoload": {
"psr-4": {
Expand All @@ -44,7 +44,7 @@
},
"scripts": {
"cs": [
"vendor/bin/ecs --fix"
"vendor/bin/pint"
],
"test": [
"vendor/bin/phpunit"
Expand Down
62 changes: 0 additions & 62 deletions ecs.php

This file was deleted.

23 changes: 15 additions & 8 deletions src/FirebaseProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ class FirebaseProject
protected array $config;

protected ?AppCheck $appCheck = null;

protected ?Auth $auth = null;

protected ?Database $database = null;

protected ?DynamicLinks $dynamicLinks = null;

protected ?Firestore $firestore = null;

protected ?Messaging $messaging = null;

protected ?RemoteConfig $remoteConfig = null;

protected ?Storage $storage = null;

public function __construct(Factory $factory, array $config)
Expand All @@ -37,7 +44,7 @@ public function __construct(Factory $factory, array $config)

public function appCheck(): AppCheck
{
if (!$this->appCheck) {
if (! $this->appCheck) {
$this->appCheck = $this->factory->createAppCheck();
}

Expand All @@ -46,7 +53,7 @@ public function appCheck(): AppCheck

public function auth(): Auth
{
if (!$this->auth) {
if (! $this->auth) {
$this->auth = $this->factory->createAuth();
}

Expand All @@ -55,7 +62,7 @@ public function auth(): Auth

public function database(): Database
{
if (!$this->database) {
if (! $this->database) {
$this->database = $this->factory->createDatabase();
}

Expand All @@ -64,7 +71,7 @@ public function database(): Database

public function dynamicLinks(): DynamicLinks
{
if (!$this->dynamicLinks) {
if (! $this->dynamicLinks) {
$this->dynamicLinks = $this->factory->createDynamicLinksService($this->config['dynamic_links']['default_domain'] ?? null);
}

Expand All @@ -73,7 +80,7 @@ public function dynamicLinks(): DynamicLinks

public function firestore(): Firestore
{
if (!$this->firestore) {
if (! $this->firestore) {
$this->firestore = $this->factory->createFirestore();
}

Expand All @@ -82,7 +89,7 @@ public function firestore(): Firestore

public function messaging(): Messaging
{
if (!$this->messaging) {
if (! $this->messaging) {
$this->messaging = $this->factory->createMessaging();
}

Expand All @@ -91,7 +98,7 @@ public function messaging(): Messaging

public function remoteConfig(): RemoteConfig
{
if (!$this->remoteConfig) {
if (! $this->remoteConfig) {
$this->remoteConfig = $this->factory->createRemoteConfig();
}

Expand All @@ -100,7 +107,7 @@ public function remoteConfig(): RemoteConfig

public function storage(): Storage
{
if (!$this->storage) {
if (! $this->storage) {
$this->storage = $this->factory->createStorage();
}

Expand Down
10 changes: 5 additions & 5 deletions src/FirebaseProjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public function __construct(Container $app)
$this->app = $app;
}

public function project(?string $name = null): FirebaseProject
public function project(string $name = null): FirebaseProject
{
$name = $name ?? $this->getDefaultProject();

if (!isset($this->projects[$name])) {
if (! isset($this->projects[$name])) {
$this->projects[$name] = $this->configure($name);
}

Expand All @@ -38,9 +38,9 @@ public function project(?string $name = null): FirebaseProject

protected function configuration(string $name): array
{
$config = $this->app->config->get('firebase.projects.' . $name);
$config = $this->app->config->get('firebase.projects.'.$name);

if (!$config) {
if (! $config) {
throw new InvalidArgumentException("Firebase project [{$name}] not configured.");
}

Expand All @@ -53,7 +53,7 @@ protected function resolveJsonCredentials(string $credentials): string
$isAbsoluteLinuxPath = \str_starts_with($credentials, '/');
$isAbsoluteWindowsPath = \str_contains($credentials, ':\\');

$isRelativePath = !$isJsonString && !$isAbsoluteLinuxPath && !$isAbsoluteWindowsPath;
$isRelativePath = ! $isJsonString && ! $isAbsoluteLinuxPath && ! $isAbsoluteWindowsPath;

return $isRelativePath ? $this->app->basePath($credentials) : $credentials;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ final class ServiceProvider extends \Illuminate\Support\ServiceProvider
public function boot(): void
{
// @codeCoverageIgnoreStart
if (!$this->app->runningInConsole()) {
if (! $this->app->runningInConsole()) {
return;
}
// @codeCoverageIgnoreEnd

$this->publishes([
__DIR__ . '/../config/firebase.php' => $this->app->configPath('firebase.php'),
__DIR__.'/../config/firebase.php' => $this->app->configPath('firebase.php'),
], 'config');
}

public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/firebase.php', 'firebase');
$this->mergeConfigFrom(__DIR__.'/../config/firebase.php', 'firebase');

$this->registerManager();
$this->registerComponents();
Expand Down
40 changes: 20 additions & 20 deletions tests/FirebaseProjectManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class FirebaseProjectManagerTest extends TestCase
{
protected function defineEnvironment($app): void
{
$app['config']->set('firebase.projects.app.credentials', __DIR__ . '/_fixtures/service_account.json');
$app['config']->set('firebase.projects.app.credentials', __DIR__.'/_fixtures/service_account.json');
}

/**
Expand Down Expand Up @@ -69,12 +69,12 @@ public function calls_are_passed_to_default_project(): void
public function credentials_can_be_configured_using_a_json_file(): void
{
// Reference credentials
$credentialsPath = \realpath(__DIR__ . '/_fixtures/service_account.json');
$credentialsPath = \realpath(__DIR__.'/_fixtures/service_account.json');
$credentials = \json_decode(\file_get_contents($credentialsPath), true);

// Set configuration and retrieve project
$projectName = 'app';
$this->app->config->set('firebase.projects.' . $projectName . '.credentials', \realpath(__DIR__ . '/_fixtures/service_account.json'));
$this->app->config->set('firebase.projects.'.$projectName.'.credentials', \realpath(__DIR__.'/_fixtures/service_account.json'));
$factory = $this->factoryForProject($projectName);

// Retrieve service account
Expand All @@ -90,12 +90,12 @@ public function credentials_can_be_configured_using_a_json_file(): void
public function json_file_credentials_can_be_used_using_the_deprecated_configuration_entry(): void
{
// Reference credentials
$credentialsPath = \realpath(__DIR__ . '/_fixtures/service_account.json');
$credentialsPath = \realpath(__DIR__.'/_fixtures/service_account.json');
$credentials = \json_decode(\file_get_contents($credentialsPath), true);

// Set configuration and retrieve project
$projectName = 'app';
$this->app->config->set('firebase.projects.' . $projectName . '.credentials.file', \realpath(__DIR__ . '/_fixtures/service_account.json'));
$this->app->config->set('firebase.projects.'.$projectName.'.credentials.file', \realpath(__DIR__.'/_fixtures/service_account.json'));
$factory = $this->factoryForProject($projectName);

// Retrieve service account
Expand All @@ -112,7 +112,7 @@ public function credentials_can_be_configured_using_an_array(): void
{
// Set configuration and retrieve project
$projectName = 'app';
$this->app->config->set('firebase.projects.' . $projectName . '.credentials', $credentials = [
$this->app->config->set('firebase.projects.'.$projectName.'.credentials', $credentials = [
'type' => 'service_account',
'project_id' => 'project',
'private_key_id' => 'private_key_id',
Expand All @@ -139,19 +139,19 @@ public function credentials_can_be_configured_using_an_array(): void
public function projects_can_have_different_credentials(): void
{
// Reference credentials
$credentialsPath = \realpath(__DIR__ . '/_fixtures/service_account.json');
$credentialsPath = \realpath(__DIR__.'/_fixtures/service_account.json');
$credentials = \json_decode(\file_get_contents($credentialsPath), true);

$secondCredentialsPath = \realpath(__DIR__ . '/_fixtures/another_service_account.json');
$secondCredentialsPath = \realpath(__DIR__.'/_fixtures/another_service_account.json');
$secondCredentials = \json_decode(\file_get_contents($secondCredentialsPath), true);

// Project names to use
$projectName = 'app';
$secondProjectName = 'another-app';

// Set service accounts explicitly
$this->app->config->set('firebase.projects.' . $projectName . '.credentials', \realpath(__DIR__ . '/_fixtures/service_account.json'));
$this->app->config->set('firebase.projects.' . $secondProjectName . '.credentials', \realpath(__DIR__ . '/_fixtures/another_service_account.json'));
$this->app->config->set('firebase.projects.'.$projectName.'.credentials', \realpath(__DIR__.'/_fixtures/service_account.json'));
$this->app->config->set('firebase.projects.'.$secondProjectName.'.credentials', \realpath(__DIR__.'/_fixtures/another_service_account.json'));

// Retrieve factories and service accounts
$factory = $this->factoryForProject($projectName);
Expand All @@ -171,8 +171,8 @@ public function projects_can_have_different_credentials(): void
public function the_realtime_database_url_can_be_configured(): void
{
$projectName = $this->app->config->get('firebase.default');
$this->app->config->set('firebase.projects.' . $projectName . '.database.url', $url = 'https://domain.tld');
$this->app->config->set('firebase.projects.' . $projectName . '.database.auth_variable_override', ['uid' => 'some-uid']);
$this->app->config->set('firebase.projects.'.$projectName.'.database.url', $url = 'https://domain.tld');
$this->app->config->set('firebase.projects.'.$projectName.'.database.auth_variable_override', ['uid' => 'some-uid']);

$database = $this->app->make(Firebase\Contract\Database::class);

Expand All @@ -187,7 +187,7 @@ public function the_realtime_database_url_can_be_configured(): void
public function the_dynamic_links_default_domain_can_be_configured(): void
{
$projectName = $this->app->config->get('firebase.default');
$this->app->config->set('firebase.projects.' . $projectName . '.dynamic_links.default_domain', $domain = 'https://domain.tld');
$this->app->config->set('firebase.projects.'.$projectName.'.dynamic_links.default_domain', $domain = 'https://domain.tld');

$dynamicLinks = $this->app->make(Firebase\Contract\DynamicLinks::class);

Expand All @@ -204,7 +204,7 @@ public function the_dynamic_links_default_domain_can_be_configured(): void
public function the_storage_default_bucket_can_be_configured(): void
{
$projectName = $this->app->config->get('firebase.default');
$this->app->config->set('firebase.projects.' . $projectName . '.storage.default_bucket', $name = 'my-bucket');
$this->app->config->set('firebase.projects.'.$projectName.'.storage.default_bucket', $name = 'my-bucket');

$storage = $this->app->make(Firebase\Contract\Storage::class);

Expand All @@ -219,7 +219,7 @@ public function the_storage_default_bucket_can_be_configured(): void
public function logging_can_be_configured(): void
{
$projectName = $this->app->config->get('firebase.default');
$this->app->config->set('firebase.projects.' . $projectName . '.logging.http_log_channel', 'stack');
$this->app->config->set('firebase.projects.'.$projectName.'.logging.http_log_channel', 'stack');

$factory = $this->factoryForProject($projectName);

Expand All @@ -234,7 +234,7 @@ public function logging_can_be_configured(): void
public function debug_logging_can_be_configured(): void
{
$projectName = $this->app->config->get('firebase.default');
$this->app->config->set('firebase.projects.' . $projectName . '.logging.http_debug_log_channel', 'stack');
$this->app->config->set('firebase.projects.'.$projectName.'.logging.http_debug_log_channel', 'stack');

$factory = $this->factoryForProject($projectName);

Expand All @@ -249,9 +249,9 @@ public function debug_logging_can_be_configured(): void
public function http_client_options_can_be_configured(): void
{
$projectName = $this->app->config->get('firebase.default');
$this->app->config->set('firebase.projects.' . $projectName . '.http_client_options.proxy', 'proxy.domain.tld');
$this->app->config->set('firebase.projects.' . $projectName . '.http_client_options.timeout', 1.23);
$this->app->config->set('firebase.projects.' . $projectName . '.http_client_options.guzzle_middlewares', [RetryMiddleware::class]);
$this->app->config->set('firebase.projects.'.$projectName.'.http_client_options.proxy', 'proxy.domain.tld');
$this->app->config->set('firebase.projects.'.$projectName.'.http_client_options.timeout', 1.23);
$this->app->config->set('firebase.projects.'.$projectName.'.http_client_options.guzzle_middlewares', [RetryMiddleware::class]);

$factory = $this->factoryForProject($projectName);

Expand Down Expand Up @@ -289,7 +289,7 @@ public function it_uses_the_laravel_cache_as_auth_token_cache(): void
$this->assertInstanceOf(CacheItemPoolInterface::class, $property->getValue($factory));
}

private function factoryForProject(?string $project = null): Factory
private function factoryForProject(string $project = null): Factory
{
$project = $this->app->make(FirebaseProjectManager::class)->project($project);

Expand Down
2 changes: 1 addition & 1 deletion tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ServiceProviderTest extends TestCase
*/
public function it_provides_components(): void
{
$this->app->config->set('firebase.projects.app.credentials', \realpath(__DIR__ . '/_fixtures/service_account.json'));
$this->app->config->set('firebase.projects.app.credentials', \realpath(__DIR__.'/_fixtures/service_account.json'));

$this->assertInstanceOf(Firebase\Contract\AppCheck::class, $this->app->make(Firebase\Contract\AppCheck::class));
$this->assertInstanceOf(Firebase\Contract\Auth::class, $this->app->make(Firebase\Contract\Auth::class));
Expand Down

0 comments on commit 8772cc4

Please sign in to comment.