diff --git a/composer.json b/composer.json index 42fe17d..0410df4 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -44,7 +44,7 @@ }, "scripts": { "cs": [ - "vendor/bin/ecs --fix" + "vendor/bin/pint" ], "test": [ "vendor/bin/phpunit" diff --git a/ecs.php b/ecs.php deleted file mode 100644 index 8d50567..0000000 --- a/ecs.php +++ /dev/null @@ -1,62 +0,0 @@ -paths([ - __DIR__ . '/src', - __DIR__ . '/tests', - __FILE__, - ]); - - $parameters = $ecsConfig->parameters(); - $parameters->set(Option::INDENTATION, 'spaces'); - $parameters->set(Option::LINE_ENDING, "\n"); - $parameters->set(Option::PARALLEL, true); - - $ecsConfig->sets([SetList::PSR_12]); - - $ecsConfig->rule(DeclareStrictTypesFixer::class); - $ecsConfig->rule(PhpUnitInternalClassFixer::class); - $ecsConfig->rule(UseArrowFunctionsFixer::class); - - $ecsConfig->ruleWithConfiguration(PhpdocAlignFixer::class, [ - 'align' => 'left', - ]); - - $ecsConfig->ruleWithConfiguration(PhpUnitMethodCasingFixer::class, [ - 'case' => 'snake_case', - ]); - $ecsConfig->ruleWithConfiguration(PhpUnitTestAnnotationFixer::class, [ - 'style' => 'annotation', - ]); -}; diff --git a/src/FirebaseProject.php b/src/FirebaseProject.php index 56d80a1..d297877 100644 --- a/src/FirebaseProject.php +++ b/src/FirebaseProject.php @@ -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) @@ -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(); } @@ -46,7 +53,7 @@ public function appCheck(): AppCheck public function auth(): Auth { - if (!$this->auth) { + if (! $this->auth) { $this->auth = $this->factory->createAuth(); } @@ -55,7 +62,7 @@ public function auth(): Auth public function database(): Database { - if (!$this->database) { + if (! $this->database) { $this->database = $this->factory->createDatabase(); } @@ -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); } @@ -73,7 +80,7 @@ public function dynamicLinks(): DynamicLinks public function firestore(): Firestore { - if (!$this->firestore) { + if (! $this->firestore) { $this->firestore = $this->factory->createFirestore(); } @@ -82,7 +89,7 @@ public function firestore(): Firestore public function messaging(): Messaging { - if (!$this->messaging) { + if (! $this->messaging) { $this->messaging = $this->factory->createMessaging(); } @@ -91,7 +98,7 @@ public function messaging(): Messaging public function remoteConfig(): RemoteConfig { - if (!$this->remoteConfig) { + if (! $this->remoteConfig) { $this->remoteConfig = $this->factory->createRemoteConfig(); } @@ -100,7 +107,7 @@ public function remoteConfig(): RemoteConfig public function storage(): Storage { - if (!$this->storage) { + if (! $this->storage) { $this->storage = $this->factory->createStorage(); } diff --git a/src/FirebaseProjectManager.php b/src/FirebaseProjectManager.php index 3a0dbe8..2081d14 100644 --- a/src/FirebaseProjectManager.php +++ b/src/FirebaseProjectManager.php @@ -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); } @@ -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."); } @@ -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; } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index a53fe12..c14930e 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -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(); diff --git a/tests/FirebaseProjectManagerTest.php b/tests/FirebaseProjectManagerTest.php index 9e0d07d..9669541 100644 --- a/tests/FirebaseProjectManagerTest.php +++ b/tests/FirebaseProjectManagerTest.php @@ -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'); } /** @@ -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 @@ -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 @@ -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', @@ -139,10 +139,10 @@ 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 @@ -150,8 +150,8 @@ public function projects_can_have_different_credentials(): void $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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index d679e7b..be68a68 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -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));