Skip to content

Commit

Permalink
Merge 5a76437 into 26389ec
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieutu committed Feb 21, 2020
2 parents 26389ec + 5a76437 commit c797c59
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
build
composer.lock
vendor
.idea
5 changes: 5 additions & 0 deletions src/Exceptions/InvalidConfiguration.php
Expand Up @@ -15,4 +15,9 @@ public static function credentialsJsonDoesNotExist(string $path)
{
return new static("Could not find a credentials file at `{$path}`.");
}

public static function credentialsTypeWrong($credentials)
{
return new static(sprintf('Credentials should be an array or the path of json file. "%s was given.', gettype($credentials)));
}
}
10 changes: 8 additions & 2 deletions src/GoogleCalendarServiceProvider.php
Expand Up @@ -35,8 +35,14 @@ protected function guardAgainstInvalidConfiguration(array $config = null)
throw InvalidConfiguration::calendarIdNotSpecified();
}

if (! file_exists($config['service_account_credentials_json'])) {
throw InvalidConfiguration::credentialsJsonDoesNotExist($config['service_account_credentials_json']);
$credentials = $config['service_account_credentials_json'];

if (! is_array($credentials) && ! is_string($credentials)) {
throw InvalidConfiguration::credentialsTypeWrong($credentials);
}

if (is_string($credentials) && ! file_exists($credentials)) {
throw InvalidConfiguration::credentialsJsonDoesNotExist($credentials);
}
}
}

0 comments on commit c797c59

Please sign in to comment.