From 08cd71dd2f8184e47e811c0d892737c71df15ddf Mon Sep 17 00:00:00 2001 From: Matt Mitchener Date: Tue, 13 Oct 2015 18:33:26 -0400 Subject: [PATCH] Applied fixes from StyleCI --- .../Authentications/UserPasswordSpec.php | 144 ++++--- .../Forrest/Authentications/WebServerSpec.php | 362 +++++++++--------- .../Providers/Laravel/LaravelCacheSpec.php | 33 +- .../Providers/Laravel/LaravelEventSpec.php | 9 +- .../Providers/Laravel/LaravelInputSpec.php | 6 +- .../Providers/Laravel/LaravelRedirectSpec.php | 3 +- .../Providers/Laravel/LaravelSessionSpec.php | 35 +- .../Forrest/Authentications/UserPassword.php | 63 +-- .../Forrest/Authentications/WebServer.php | 103 ++--- src/Omniphx/Forrest/Client.php | 319 ++++++++------- .../Exceptions/MissingKeyException.php | 8 +- .../MissingRefreshTokenException.php | 8 +- .../Exceptions/MissingTokenException.php | 8 +- .../Exceptions/SalesforceException.php | 8 +- .../Exceptions/TokenExpiredException.php | 8 +- .../Interfaces/AuthenticationInterface.php | 29 +- .../Forrest/Interfaces/EventInterface.php | 24 +- .../Forrest/Interfaces/InputInterface.php | 23 +- .../Forrest/Interfaces/RedirectInterface.php | 23 +- .../Forrest/Interfaces/StorageInterface.php | 120 +++--- .../Interfaces/UserPasswordInterface.php | 8 +- .../Forrest/Interfaces/WebServerInterface.php | 10 +- .../Providers/Laravel/Facades/Forrest.php | 22 +- .../Laravel/ForrestServiceProvider.php | 127 +++--- .../Providers/Laravel/LaravelCache.php | 121 +++--- .../Providers/Laravel/LaravelEvent.php | 36 +- .../Providers/Laravel/LaravelInput.php | 31 +- .../Providers/Laravel/LaravelRedirect.php | 29 +- .../Providers/Laravel/LaravelSession.php | 109 +++--- .../Laravel/LaravelStorageProvider.php | 26 +- .../Providers/Laravel/Routes/UserPassword.php | 5 +- .../Providers/Laravel/Routes/WebServer.php | 8 +- .../Providers/Laravel4/Facades/Forrest.php | 22 +- .../Laravel4/ForrestServiceProvider.php | 35 +- .../Providers/Laravel4/LaravelCache.php | 121 +++--- .../Providers/Laravel4/LaravelEvent.php | 36 +- .../Providers/Laravel4/LaravelInput.php | 31 +- .../Providers/Laravel4/LaravelRedirect.php | 29 +- .../Providers/Laravel4/LaravelSession.php | 111 +++--- .../Laravel4/LaravelStorageProvider.php | 28 +- .../Laravel4/Routes/UserPassword.php | 5 +- .../Providers/Laravel4/Routes/WebServer.php | 8 +- .../Lumen/ForrestServiceProvider.php | 36 +- src/config/config.php | 141 +++---- 44 files changed, 1339 insertions(+), 1132 deletions(-) diff --git a/spec/Omniphx/Forrest/Authentications/UserPasswordSpec.php b/spec/Omniphx/Forrest/Authentications/UserPasswordSpec.php index e10f46d..e51e275 100644 --- a/spec/Omniphx/Forrest/Authentications/UserPasswordSpec.php +++ b/spec/Omniphx/Forrest/Authentications/UserPasswordSpec.php @@ -2,59 +2,58 @@ namespace spec\Omniphx\Forrest\Authentications; -use PhpSpec\ObjectBehavior; -use Prophecy\Argument; - use GuzzleHttp\ClientInterface; -use GuzzleHttp\Message\ResponseInterface; use GuzzleHttp\Message\RequestInterface; -use Omniphx\Forrest\Interfaces\StorageInterface; -use Omniphx\Forrest\Interfaces\RedirectInterface; -use Omniphx\Forrest\Interfaces\InputInterface; +use GuzzleHttp\Message\ResponseInterface; use Omniphx\Forrest\Interfaces\EventInterface; +use Omniphx\Forrest\Interfaces\InputInterface; +use Omniphx\Forrest\Interfaces\RedirectInterface; +use Omniphx\Forrest\Interfaces\StorageInterface; +use PhpSpec\ObjectBehavior; +use Prophecy\Argument; class UserPasswordSpec extends ObjectBehavior { - function let( + public function let( ClientInterface $mockedClient, ResponseInterface $mockedResponse, RequestInterface $mockedRequest, StorageInterface $mockedStorage, RedirectInterface $mockedRedirect, InputInterface $mockedInput, - EventInterface $mockedEvent) { - - $settings = array( + EventInterface $mockedEvent) + { + $settings = [ 'authenticationFlow' => 'UserPassword', - 'credentials' => array( + 'credentials' => [ 'consumerKey' => 'testingClientId', 'consumerSecret' => 'testingClientSecret', 'callbackURI' => 'callbackURL', 'loginURL' => 'https://login.salesforce.com', - 'username' => '', - 'password' => '', + 'username' => '', + 'password' => '', - ), - 'parameters' => array( + ], + 'parameters' => [ 'display' => 'popup', 'immediate' => 'false', 'state' => '', 'scope' => '', - ), - 'instanceURL' => '', + ], + 'instanceURL' => '', 'authRedirect' => 'redirectURL', - 'version' => '30.0', - 'defaults' => array( + 'version' => '30.0', + 'defaults' => [ 'method' => 'get', 'format' => 'json', 'compression' => false, 'compressionType' => 'gzip', - ), - 'language' => 'en_US' - ); + ], + 'language' => 'en_US', + ]; $mockedStorage->get('resources')->willReturn([ - 'sobjects' => '/services/data/v30.0/sobjects', + 'sobjects' => '/services/data/v30.0/sobjects', 'connect' => '/services/data/v30.0/connect', 'query' => '/services/data/v30.0/query', 'theme' => '/services/data/v30.0/theme', @@ -68,20 +67,20 @@ function let( 'flexiPage' => '/services/data/v30.0/flexiPage', 'search' => '/services/data/v30.0/search', 'quickActions' => '/services/data/v30.0/quickActions', - 'appMenu' => '/services/data/v30.0/appMenu']); + 'appMenu' => '/services/data/v30.0/appMenu', ]); $mockedStorage->get('version')->willReturn([ - 'url' => 'resourceURLs']); + 'url' => 'resourceURLs', ]); $mockedStorage->getTokenData()->willReturn([ 'access_token' => 'accessToken', 'id' => 'https://login.salesforce.com/id/00Di0000000XXXXXX/005i0000000xxxxXXX', 'instance_url' => 'https://na00.salesforce.com', - 'token_type' => 'Oauth']); + 'token_type' => 'Oauth', ]); $mockedStorage->putTokenData(Argument::any())->willReturn(null); - $mockedStorage->put(Argument::any(),Argument::any())->willReturn(null); + $mockedStorage->put(Argument::any(), Argument::any())->willReturn(null); $mockedClient->send(Argument::any())->willReturn($mockedResponse); - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); - $mockedClient->post(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedResponse); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); + $mockedClient->post(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedResponse); $this->beConstructedWith( $mockedClient, @@ -90,36 +89,35 @@ function let( $mockedInput, $mockedEvent, $settings); - } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Omniphx\Forrest\Authentications\UserPassword'); } - function it_should_authenticate( + public function it_should_authenticate( ResponseInterface $versionResponse, ClientInterface $mockedClient) { $mockedClient->send(Argument::any())->shouldBeCalled(1)->willReturn($versionResponse); - $versionResponse->json()->shouldBeCalled()->willReturn([['version'=>'30.0'],['version'=>'31.0']]); + $versionResponse->json()->shouldBeCalled()->willReturn([['version' => '30.0'],['version' => '31.0']]); $this->authenticate('url')->shouldReturn(null); } - function it_should_refresh( + public function it_should_refresh( ResponseInterface $mockedResponse, StorageInterface $mockedStorage) { - $mockedResponse->json()->shouldBeCalled()->willReturn(['key'=>'value']); + $mockedResponse->json()->shouldBeCalled()->willReturn(['key' => 'value']); $mockedStorage->putTokenData(Argument::type('array'))->shouldBeCalled(); $this->refresh()->shouldReturn(null); } - function it_should_return_the_request( + public function it_should_return_the_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) @@ -128,133 +126,132 @@ function it_should_return_the_request( $mockedResponse->json()->shouldBeCalled()->willReturn('worked'); - $this->request('url',['key'=>'value'])->shouldReturn('worked'); + $this->request('url', ['key' => 'value'])->shouldReturn('worked'); } - function it_should_refresh_the_token_if_response_throws_error( + public function it_should_refresh_the_token_if_response_throws_error( ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->send($mockedRequest)->willThrow('\Omniphx\Forrest\Exceptions\TokenExpiredException'); //This might seem counter-intuitive. We are throwing an exception with the send() method, but we can't stop it. Since we are calling the send() method twice, the behavior is correct for it to throw an exception. Actual behavior would never throw the exception, it would return a response. - $this->shouldThrow('\Omniphx\Forrest\Exceptions\TokenExpiredException')->duringRequest('url',['key'=>'value']); + $this->shouldThrow('\Omniphx\Forrest\Exceptions\TokenExpiredException')->duringRequest('url', ['key' => 'value']); } - function it_should_revoke_the_authentication_token(ClientInterface $mockedClient) + public function it_should_revoke_the_authentication_token(ClientInterface $mockedClient) { - $mockedClient->post(Argument::type('string'),Argument::type('array'))->shouldBeCalled(); + $mockedClient->post(Argument::type('string'), Argument::type('array'))->shouldBeCalled(); $this->revoke()->shouldReturn(null); } //Client - function it_should_return_the_versions(ResponseInterface $mockedResponse) + public function it_should_return_the_versions(ResponseInterface $mockedResponse) { - $mockedResponse->json()->shouldBeCalled()->willReturn(array('version'=>'29.0','version'=>'30.0')); + $mockedResponse->json()->shouldBeCalled()->willReturn(['version' => '29.0','version' => '30.0']); - $this->versions()->shouldReturn(array('version'=>'29.0','version'=>'30.0')); + $this->versions()->shouldReturn(['version' => '29.0','version' => '30.0']); } - function it_should_return_resources(ResponseInterface $mockedResponse) + public function it_should_return_resources(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('versionURLs'); $this->resources()->shouldReturn('versionURLs'); } - function it_should_return_identity (ResponseInterface $mockedResponse) + public function it_should_return_identity(ResponseInterface $mockedResponse) { $mockedResponse->json()->willReturn('Identity'); $this->identity()->shouldReturn('Identity'); } - function it_should_return_limits( + public function it_should_return_limits( StorageInterface $mockedStorage, ResponseInterface $mockedResponse) { - $mockedStorage->get('version')->shouldBeCalled()->willReturn(array('url'=>'versionURL')); + $mockedStorage->get('version')->shouldBeCalled()->willReturn(['url' => 'versionURL']); $mockedResponse->json()->shouldBeCalled()->willReturn('limits'); $this->limits()->shouldReturn('limits'); } - function it_should_return_describe( + public function it_should_return_describe( StorageInterface $mockedStorage, ResponseInterface $mockedResponse) { - $mockedStorage->get('version')->shouldBeCalled()->willReturn(array('url'=>'versionURL')); + $mockedStorage->get('version')->shouldBeCalled()->willReturn(['url' => 'versionURL']); $mockedResponse->json()->shouldBeCalled()->willReturn('describe'); - $this->describe()->shouldReturn('describe'); + $this->describe()->shouldReturn('describe'); } - function it_should_return_query(ResponseInterface $mockedResponse) + public function it_should_return_query(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('query'); $this->query('query')->shouldReturn('query'); } - function it_should_return_query_next(ResponseInterface $mockedResponse) + public function it_should_return_query_next(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('query'); $this->next('nextUrl')->shouldReturn('query'); } - function it_should_return_queryExplain(ResponseInterface $mockedResponse) + public function it_should_return_queryExplain(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('queryExplain'); $this->queryExplain('query')->shouldReturn('queryExplain'); } - function it_should_return_queryAll(ResponseInterface $mockedResponse) + public function it_should_return_queryAll(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('queryAll'); $this->queryAll('query')->shouldReturn('queryAll'); } - function it_should_return_quickActions(ResponseInterface $mockedResponse) + public function it_should_return_quickActions(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('quickActions'); $this->quickActions()->shouldReturn('quickActions'); } - function it_should_return_search(ResponseInterface $mockedResponse) + public function it_should_return_search(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('search'); $this->search('query')->shouldReturn('search'); } - function it_should_return_ScopeOrder(ResponseInterface $mockedResponse) + public function it_should_return_ScopeOrder(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('searchScopeOrder'); $this->scopeOrder()->shouldReturn('searchScopeOrder'); } - function it_should_return_searchLayouts(ResponseInterface $mockedResponse) + public function it_should_return_searchLayouts(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('searchLayouts'); $this->searchLayouts('objectList')->shouldReturn('searchLayouts'); } - function it_should_return_suggestedArticles(ResponseInterface $mockedResponse) + public function it_should_return_suggestedArticles(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('suggestedArticles'); $this->suggestedArticles('query')->shouldReturn('suggestedArticles'); } - function it_should_return_suggestedQueries(ResponseInterface $mockedResponse) + public function it_should_return_suggestedQueries(ResponseInterface $mockedResponse) { $mockedResponse->json()->shouldBeCalled()->willReturn('searchSuggestedQueries'); @@ -263,31 +260,30 @@ function it_should_return_suggestedQueries(ResponseInterface $mockedResponse) //Resource class - function it_returns_a_resource( + public function it_returns_a_resource( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest(Argument::type('string'),Argument::type('string'),Argument::type('array'))->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::type('string'), Argument::type('string'), Argument::type('array'))->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource'); $mockedResponse->xml()->shouldBeCalled()->willReturn('xmlResource'); - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'abc', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'abc', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); - $this->request('uri',[])->shouldReturn('jsonResource'); - $this->request('uri',['format'=>'xml'])->shouldReturn('xmlResource'); + $this->request('uri', [])->shouldReturn('jsonResource'); + $this->request('uri', ['format' => 'xml'])->shouldReturn('xmlResource'); } - function it_allows_access_to_the_guzzle_client( + public function it_allows_access_to_the_guzzle_client( ClientInterface $mockedClient) { $this->getClient()->shouldReturn($mockedClient); } - -} \ No newline at end of file +} diff --git a/spec/Omniphx/Forrest/Authentications/WebServerSpec.php b/spec/Omniphx/Forrest/Authentications/WebServerSpec.php index 58a82f3..65feccd 100644 --- a/spec/Omniphx/Forrest/Authentications/WebServerSpec.php +++ b/spec/Omniphx/Forrest/Authentications/WebServerSpec.php @@ -2,20 +2,19 @@ namespace spec\Omniphx\Forrest\Authentications; -use PhpSpec\ObjectBehavior; -use Prophecy\Argument; - use GuzzleHttp\ClientInterface; -use GuzzleHttp\Message\ResponseInterface; use GuzzleHttp\Message\RequestInterface; -use Omniphx\Forrest\Interfaces\StorageInterface; -use Omniphx\Forrest\Interfaces\RedirectInterface; -use Omniphx\Forrest\Interfaces\InputInterface; +use GuzzleHttp\Message\ResponseInterface; use Omniphx\Forrest\Interfaces\EventInterface; +use Omniphx\Forrest\Interfaces\InputInterface; +use Omniphx\Forrest\Interfaces\RedirectInterface; +use Omniphx\Forrest\Interfaces\StorageInterface; +use PhpSpec\ObjectBehavior; +use Prophecy\Argument; class WebServerSpec extends ObjectBehavior { - function let( + public function let( ClientInterface $mockedClient, ResponseInterface $mockedResponse, RequestInterface $mockedRequest, @@ -24,42 +23,42 @@ function let( InputInterface $mockedInput, EventInterface $mockedEvent) { - $settings = array( - 'credentials' => array( + $settings = [ + 'credentials' => [ 'consumerKey' => 'testingClientId', - 'consumerSecret' => 'testingClientSecret', - 'callbackURI' => 'callbackURL', - 'loginURL' => 'https://login.salesforce.com', - ), + 'consumerSecret' => 'testingClientSecret', + 'callbackURI' => 'callbackURL', + 'loginURL' => 'https://login.salesforce.com', + ], 'authenticationFlow' => 'WebServer', - 'parameters' => array( + 'parameters' => [ 'display' => 'popup', 'immediate' => 'false', 'state' => '', 'scope' => '', 'prompt' => '', - ), - 'instanceURL' => '', + ], + 'instanceURL' => '', 'authRedirect' => 'redirectURL', - 'version' => '30.0', - 'defaults' => array( + 'version' => '30.0', + 'defaults' => [ 'method' => 'get', 'format' => 'json', 'compression' => false, 'compressionType' => 'gzip', - ), - 'language' => 'en_US' - ); + ], + 'language' => 'en_US', + ]; $token = [ 'access_token' => 'xxxxaccess.tokenxxxx', 'id' => 'https://login.salesforce.com/id/00Di0000000XXXXXX/005i0000000xxxxXXX', 'instance_url' => 'https://na##.salesforce.com', 'token_type' => 'Bearer', - 'refresh_token' => 'xxxxrefresh.tokenxxxx']; + 'refresh_token' => 'xxxxrefresh.tokenxxxx', ]; $resources = [ - 'sobjects' => '/services/data/v30.0/sobjects', + 'sobjects' => '/services/data/v30.0/sobjects', 'connect' => '/services/data/v30.0/connect', 'query' => '/services/data/v30.0/query', 'theme' => '/services/data/v30.0/theme', @@ -73,12 +72,12 @@ function let( 'flexiPage' => '/services/data/v30.0/flexiPage', 'search' => '/services/data/v30.0/search', 'quickActions' => '/services/data/v30.0/quickActions', - 'appMenu' => '/services/data/v30.0/appMenu']; + 'appMenu' => '/services/data/v30.0/appMenu', ]; //Storage stubs $mockedStorage->get('resources')->willReturn($resources); $mockedStorage->get('version')->willReturn([ - 'url' => '/resourceURL']); + 'url' => '/resourceURL', ]); $mockedStorage->getTokenData()->willReturn($token); $mockedStorage->putTokenData(Argument::type('array')); @@ -94,33 +93,33 @@ function let( $settings); } - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Omniphx\Forrest\Authentications\WebServer'); } - function it_should_authenticate(RedirectInterface $mockedRedirect) + public function it_should_authenticate(RedirectInterface $mockedRedirect) { $mockedRedirect->to(Argument::any())->willReturn('redirectURL'); $this->authenticate()->shouldReturn('redirectURL'); } - function it_should_callback( + public function it_should_callback( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $tokenResponse, ResponseInterface $versionResponse, StorageInterface $mockedStorage) { - $mockedClient->post('https://login.salesforce.com/services/oauth2/token',Argument::type('array'))->shouldBeCalled(1)->willReturn($tokenResponse); + $mockedClient->post('https://login.salesforce.com/services/oauth2/token', Argument::type('array'))->shouldBeCalled(1)->willReturn($tokenResponse); $mockedClient->send(Argument::any())->shouldBeCalled(1)->willReturn($versionResponse); - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); - $tokenResponse->json()->shouldBeCalled(1)->willReturn(array( + $tokenResponse->json()->shouldBeCalled(1)->willReturn([ 'access_token' => 'value1', - 'refresh_token' => 'value2')); + 'refresh_token' => 'value2', ]); - $versionResponse->json()->shouldBeCalled()->willReturn([['version'=>'30.0'],['version'=>'31.0']]); + $versionResponse->json()->shouldBeCalled()->willReturn([['version' => '30.0'],['version' => '31.0']]); $mockedStorage->putTokenData(Argument::type('array'))->shouldBeCalled(); $mockedStorage->putRefreshToken(Argument::exact('value2'))->shouldBeCalled(); @@ -129,7 +128,7 @@ function it_should_callback( $this->callback()->shouldReturn(null); } - function it_should_refresh( + public function it_should_refresh( ClientInterface $mockedClient, ResponseInterface $mockedResponse, StorageInterface $mockedStorage) @@ -140,34 +139,33 @@ function it_should_refresh( ->shouldBeCalled() ->willReturn($mockedResponse); - $mockedResponse->json()->shouldBeCalled()->willReturn(['key'=>'value']); + $mockedResponse->json()->shouldBeCalled()->willReturn(['key' => 'value']); $mockedStorage->putTokenData(Argument::type('array'))->shouldBeCalled(); $this->refresh('token')->shouldReturn(null); - } - function it_should_return_the_request( + public function it_should_return_the_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { $mockedClient->send($mockedRequest)->willReturn($mockedResponse); - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('worked'); - $this->request('url',['key'=>'value'])->shouldReturn('worked'); + $this->request('url', ['key' => 'value'])->shouldReturn('worked'); } - function it_should_refresh_the_token_if_response_throws_error( + public function it_should_refresh_the_token_if_response_throws_error( ClientInterface $mockedClient, RequestInterface $mockedRequest, StorageInterface $mockedStorage, ResponseInterface $mockedResponse) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedClient->send($mockedRequest)->willThrow('\Omniphx\Forrest\Exceptions\TokenExpiredException'); $mockedStorage->getRefreshToken()->shouldBeCalled()->willReturn('refresh_token'); @@ -176,462 +174,462 @@ function it_should_refresh_the_token_if_response_throws_error( ->shouldBeCalled() ->willReturn($mockedResponse); - $mockedResponse->json()->shouldBeCalled(1)->willReturn(['key'=>'value']); + $mockedResponse->json()->shouldBeCalled(1)->willReturn(['key' => 'value']); $mockedStorage->putTokenData(Argument::type('array'))->shouldBeCalled(); //This might seem counter-intuitive. We are throwing an exception with the send() method, but we can't stop it. Since we are calling the send() method twice, the behavior is correct for it to throw an exception. Actual behavior would never throw the exception, it would return a response. - $this->shouldThrow('\Omniphx\Forrest\Exceptions\TokenExpiredException')->duringRequest('url',['key'=>'value']); + $this->shouldThrow('\Omniphx\Forrest\Exceptions\TokenExpiredException')->duringRequest('url', ['key' => 'value']); } - function it_should_not_call_refresh_method_if_there_is_no_token( + public function it_should_not_call_refresh_method_if_there_is_no_token( ClientInterface $mockedClient, RequestInterface $failedRequest, StorageInterface $mockedStorage) { $mockedClient->send($failedRequest)->willThrow('\Omniphx\Forrest\Exceptions\TokenExpiredException'); - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($failedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($failedRequest); $mockedStorage->getRefreshToken()->willThrow('\Omniphx\Forrest\Exceptions\MissingRefreshTokenException'); - $this->shouldThrow('Omniphx\Forrest\Exceptions\MissingRefreshTokenException')->duringRequest('url',['key'=>'value']); + $this->shouldThrow('Omniphx\Forrest\Exceptions\MissingRefreshTokenException')->duringRequest('url', ['key' => 'value']); } //Client class - function it_should_revoke_the_authentication_token(ClientInterface $mockedClient) + public function it_should_revoke_the_authentication_token(ClientInterface $mockedClient) { - $mockedClient->post(Argument::type('string'),Argument::type('array'))->shouldBeCalled(); + $mockedClient->post(Argument::type('string'), Argument::type('array'))->shouldBeCalled(); $this->revoke()->shouldReturn(null); } - function it_should_return_the_versions( + public function it_should_return_the_versions( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); - $mockedResponse->json()->shouldBeCalled()->willReturn(array('version'=>'29.0','version'=>'30.0')); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); + $mockedResponse->json()->shouldBeCalled()->willReturn(['version' => '29.0','version' => '30.0']); - $this->versions()->shouldReturn(array('version'=>'29.0','version'=>'30.0')); + $this->versions()->shouldReturn(['version' => '29.0','version' => '30.0']); } - function it_should_return_resources( + public function it_should_return_resources( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('versionURLs'); $this->resources()->shouldReturn('versionURLs'); } - function it_should_return_identity ( + public function it_should_return_identity( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->willReturn('Identity'); $this->identity()->shouldReturn('Identity'); } - function it_should_return_limits( + public function it_should_return_limits( StorageInterface $mockedStorage, ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); - $mockedStorage->get('version')->shouldBeCalled()->willReturn(array('url'=>'versionURL')); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); + $mockedStorage->get('version')->shouldBeCalled()->willReturn(['url' => 'versionURL']); $mockedResponse->json()->shouldBeCalled()->willReturn('limits'); $this->limits()->shouldReturn('limits'); } - function it_should_return_describe( + public function it_should_return_describe( StorageInterface $mockedStorage, ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); - $mockedStorage->get('version')->shouldBeCalled()->willReturn(array('url'=>'versionURL')); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); + $mockedStorage->get('version')->shouldBeCalled()->willReturn(['url' => 'versionURL']); $mockedResponse->json()->shouldBeCalled()->willReturn('describe'); - $this->describe()->shouldReturn('describe'); + $this->describe()->shouldReturn('describe'); } - function it_should_return_query( + public function it_should_return_query( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('query'); $this->query('query')->shouldReturn('query'); } - function it_should_return_next_query( + public function it_should_return_next_query( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('query'); $this->next('nextUrl')->shouldReturn('query'); } - function it_should_return_queryExplain( + public function it_should_return_queryExplain( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('queryExplain'); $this->queryExplain('query')->shouldReturn('queryExplain'); } - function it_should_return_queryAll( + public function it_should_return_queryAll( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('queryAll'); $this->queryAll('query')->shouldReturn('queryAll'); } - function it_should_return_quickActions( + public function it_should_return_quickActions( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('quickActions'); $this->quickActions()->shouldReturn('quickActions'); } - function it_should_return_search( + public function it_should_return_search( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('search'); $this->search('query')->shouldReturn('search'); } - function it_should_return_ScopeOrder( + public function it_should_return_ScopeOrder( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('searchScopeOrder'); $this->scopeOrder()->shouldReturn('searchScopeOrder'); } - function it_should_return_searchLayouts( + public function it_should_return_searchLayouts( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('searchLayouts'); $this->searchLayouts('objectList')->shouldReturn('searchLayouts'); } - function it_should_return_suggestedArticles( + public function it_should_return_suggestedArticles( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest('get','https://na##.salesforce.com/services/data/v30.0/search/suggestTitleMatches?q=query&language=en_US&publishStatus=Online&foo=bar&flim=flam',Argument::type('Array'))->willReturn($mockedRequest); + $mockedClient->createRequest('get', 'https://na##.salesforce.com/services/data/v30.0/search/suggestTitleMatches?q=query&language=en_US&publishStatus=Online&foo=bar&flim=flam', Argument::type('Array'))->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('suggestedArticles'); - $this->suggestedArticles('query', ['parameters'=>['foo'=>'bar','flim'=>'flam']])->shouldReturn('suggestedArticles'); + $this->suggestedArticles('query', ['parameters' => ['foo' => 'bar','flim' => 'flam']])->shouldReturn('suggestedArticles'); } - function it_should_return_suggestedQueries( + public function it_should_return_suggestedQueries( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest('get','https://na##.salesforce.com/services/data/v30.0/search/suggestSearchQueries?q=query&language=en_US&foo=bar&flim=flam',Argument::type('array'))->willReturn($mockedRequest); + $mockedClient->createRequest('get', 'https://na##.salesforce.com/services/data/v30.0/search/suggestSearchQueries?q=query&language=en_US&foo=bar&flim=flam', Argument::type('array'))->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('searchSuggestedQueries'); - $this->suggestedQueries('query', ['parameters'=>['foo'=>'bar','flim'=>'flam']])->shouldReturn('searchSuggestedQueries'); + $this->suggestedQueries('query', ['parameters' => ['foo' => 'bar','flim' => 'flam']])->shouldReturn('searchSuggestedQueries'); } - function it_should_return_custom_request( + public function it_should_return_custom_request( ResponseInterface $mockedResponse, ClientInterface $mockedClient, RequestInterface $mockedRequest) { - $mockedClient->createRequest('get','https://na##.salesforce.com/services/apexrest/FieldCase?foo=bar',Argument::type('array'))->willReturn($mockedRequest); + $mockedClient->createRequest('get', 'https://na##.salesforce.com/services/apexrest/FieldCase?foo=bar', Argument::type('array'))->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn('customRequest'); - $this->custom('/FieldCase',['parameters'=>['foo'=>'bar']])->shouldReturn('customRequest'); + $this->custom('/FieldCase', ['parameters' => ['foo' => 'bar']])->shouldReturn('customRequest'); } //Resource class - function it_returns_a_resource( + public function it_returns_a_resource( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest(Argument::type('string'),Argument::type('string'),Argument::type('array'))->willReturn($mockedRequest); + $mockedClient->createRequest(Argument::type('string'), Argument::type('string'), Argument::type('array'))->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource'); $mockedResponse->xml()->shouldBeCalled()->willReturn('xmlResource'); - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'abc', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'abc', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); - $this->request('uri',[])->shouldReturn('jsonResource'); - $this->request('uri',['format'=>'xml'])->shouldReturn('xmlResource'); + $this->request('uri', [])->shouldReturn('jsonResource'); + $this->request('uri', ['format' => 'xml'])->shouldReturn('xmlResource'); } - function it_should_format_header_in_json( + public function it_should_format_header_in_json( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, - ResponseInterface $mockedResponse){ - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'accesstoken', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + ResponseInterface $mockedResponse) + { + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'accesstoken', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); $mockedClient->createRequest( - "get", - "uri", - ['headers'=>['Authorization' => 'bearer accesstoken', 'Accept' => 'application/json', 'Content-Type' => 'application/json']]) + 'get', + 'uri', + ['headers' => ['Authorization' => 'bearer accesstoken', 'Accept' => 'application/json', 'Content-Type' => 'application/json']]) ->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource'); - $this->request('uri',[])->shouldReturn('jsonResource'); + $this->request('uri', [])->shouldReturn('jsonResource'); } - function it_should_format_header_in_xml( + public function it_should_format_header_in_xml( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, - ResponseInterface $mockedResponse){ - - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'accesstoken', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + ResponseInterface $mockedResponse) + { + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'accesstoken', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); $mockedClient->createRequest( - "get", - "uri", - ['headers'=>['Authorization' => 'bearer accesstoken', 'Accept' => 'application/xml', 'Content-Type' => 'application/xml']]) + 'get', + 'uri', + ['headers' => ['Authorization' => 'bearer accesstoken', 'Accept' => 'application/xml', 'Content-Type' => 'application/xml']]) ->shouldBeCalled()->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); $mockedResponse->xml()->shouldBeCalled()->willReturn('xmlResource'); - $this->request('uri',['format'=>'xml'])->shouldReturn('xmlResource'); + $this->request('uri', ['format' => 'xml'])->shouldReturn('xmlResource'); } - function it_should_format_header_in_urlencoding( + public function it_should_format_header_in_urlencoding( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, - ResponseInterface $mockedResponse){ - - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'accesstoken', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + ResponseInterface $mockedResponse) + { + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'accesstoken', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); $mockedClient->createRequest( - "get", - "uri", - ['headers'=>['Authorization' => 'bearer accesstoken', 'Accept' => 'application/x-www-form-urlencoded', 'Content-Type' => 'application/x-www-form-urlencoded']]) + 'get', + 'uri', + ['headers' => ['Authorization' => 'bearer accesstoken', 'Accept' => 'application/x-www-form-urlencoded', 'Content-Type' => 'application/x-www-form-urlencoded']]) ->shouldBeCalled()->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); - $this->request('uri',['format'=>'urlencoded'])->shouldReturn($mockedResponse); + $this->request('uri', ['format' => 'urlencoded'])->shouldReturn($mockedResponse); } - function it_should_format_header_with_gzip( + public function it_should_format_header_with_gzip( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, - ResponseInterface $mockedResponse){ - - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'accesstoken', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + ResponseInterface $mockedResponse) + { + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'accesstoken', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); $mockedClient->createRequest( - "get", - "uri", - ['headers'=>["Authorization" => "bearer accesstoken", "Accept" => "application/json", "Content-Type" => "application/json", "Accept-Encoding" => "gzip", "Content-Encoding" => "gzip"]]) + 'get', + 'uri', + ['headers' => ['Authorization' => 'bearer accesstoken', 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Accept-Encoding' => 'gzip', 'Content-Encoding' => 'gzip']]) ->shouldBeCalled()->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource'); - $this->request('uri',['compression'=>true, 'compressionType'=>'gzip'])->shouldReturn('jsonResource'); + $this->request('uri', ['compression' => true, 'compressionType' => 'gzip'])->shouldReturn('jsonResource'); } - function it_should_format_header_with_deflate( + public function it_should_format_header_with_deflate( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, - ResponseInterface $mockedResponse){ - - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'accesstoken', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + ResponseInterface $mockedResponse) + { + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'accesstoken', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); $mockedClient->createRequest( - "get", - "uri", - ['headers'=>["Authorization" => "bearer accesstoken", "Accept" => "application/json", "Content-Type" => "application/json", "Accept-Encoding" => "deflate", "Content-Encoding" => "deflate"]]) + 'get', + 'uri', + ['headers' => ['Authorization' => 'bearer accesstoken', 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Accept-Encoding' => 'deflate', 'Content-Encoding' => 'deflate']]) ->shouldBeCalled()->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource'); - $this->request('uri',['compression'=>true, 'compressionType'=>'deflate'])->shouldReturn('jsonResource'); + $this->request('uri', ['compression' => true, 'compressionType' => 'deflate'])->shouldReturn('jsonResource'); } - function it_should_format_header_without_compression( + public function it_should_format_header_without_compression( ClientInterface $mockedClient, StorageInterface $mockedStorage, RequestInterface $mockedRequest, - ResponseInterface $mockedResponse){ - - $mockedStorage->getTokenData()->willReturn(array( - 'access_token' =>'accesstoken', - 'instance_url' =>'def', - 'token_type' =>'bearer')); + ResponseInterface $mockedResponse) + { + $mockedStorage->getTokenData()->willReturn([ + 'access_token' => 'accesstoken', + 'instance_url' => 'def', + 'token_type' => 'bearer', ]); $mockedClient->createRequest( - "get", - "uri", - ['headers'=>["Authorization" => "bearer accesstoken", "Accept" => "application/json", "Content-Type" => "application/json"]]) + 'get', + 'uri', + ['headers' => ['Authorization' => 'bearer accesstoken', 'Accept' => 'application/json', 'Content-Type' => 'application/json']]) ->shouldBeCalled()->willReturn($mockedRequest); $mockedClient->send(Argument::any())->willReturn($mockedResponse); $mockedResponse->json()->shouldBeCalled()->willReturn('jsonResource'); - $this->request('uri',['compression'=>false])->shouldReturn('jsonResource'); + $this->request('uri', ['compression' => false])->shouldReturn('jsonResource'); } - function it_should_allow_a_get_request( + public function it_should_allow_a_get_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest('GET',Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest('GET', Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn($mockedResponse); $this->get('uri')->shouldReturn($mockedResponse); } - function it_should_allow_a_post_request( + public function it_should_allow_a_post_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest('POST',Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest('POST', Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn($mockedResponse); - $this->post('uri', array('test'=>'param'))->shouldReturn($mockedResponse); + $this->post('uri', ['test' => 'param'])->shouldReturn($mockedResponse); } - function it_should_allow_a_put_request( + public function it_should_allow_a_put_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest('PUT',Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest('PUT', Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn($mockedResponse); - $this->put('uri', array('test'=>'param'))->shouldReturn($mockedResponse); + $this->put('uri', ['test' => 'param'])->shouldReturn($mockedResponse); } - function it_should_allow_a_patch_request( + public function it_should_allow_a_patch_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest('PATCH',Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest('PATCH', Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn($mockedResponse); - $this->patch('uri', array('test'=>'param'))->shouldReturn($mockedResponse); + $this->patch('uri', ['test' => 'param'])->shouldReturn($mockedResponse); } - function it_should_allow_a_head_request( + public function it_should_allow_a_head_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest('HEAD',Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest('HEAD', Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn($mockedResponse); $this->head('uri')->shouldReturn($mockedResponse); } - function it_should_allow_a_delete_request( + public function it_should_allow_a_delete_request( ClientInterface $mockedClient, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest('DELETE',Argument::any(),Argument::any())->willReturn($mockedRequest); + $mockedClient->createRequest('DELETE', Argument::any(), Argument::any())->willReturn($mockedRequest); $mockedResponse->json()->shouldBeCalled()->willReturn($mockedResponse); $this->delete('delete')->shouldReturn($mockedResponse); } - function it_allows_access_to_the_guzzle_client( + public function it_allows_access_to_the_guzzle_client( ClientInterface $mockedClient) { $this->getClient()->shouldReturn($mockedClient); } - function it_should_fire_a_response_event ( + public function it_should_fire_a_response_event( ClientInterface $mockedClient, EventInterface $mockedEvent, RequestInterface $mockedRequest, ResponseInterface $mockedResponse) { - $mockedClient->createRequest(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedRequest); - $mockedClient->send(Argument::any(),Argument::any(),Argument::any())->willReturn($mockedResponse); + $mockedClient->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedRequest); + $mockedClient->send(Argument::any(), Argument::any(), Argument::any())->willReturn($mockedResponse); $mockedEvent->fire('forrest.response', Argument::any())->shouldBeCalled(); $this->versions(); } - } diff --git a/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php b/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php index ebcce20..3f116bc 100644 --- a/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php +++ b/spec/Omniphx/Forrest/Providers/Laravel/LaravelCacheSpec.php @@ -2,26 +2,25 @@ namespace spec\Omniphx\Forrest\Providers\Laravel; +use Illuminate\Cache\CacheManager as Cache; +use Illuminate\Config\Repository as Config; use PhpSpec\ObjectBehavior; use Prophecy\Argument; -use Illuminate\Config\Repository as Config; -use Illuminate\Cache\CacheManager as Cache; class LaravelCacheSpec extends ObjectBehavior { - - function let(Config $config, Cache $cache) + public function let(Config $config, Cache $cache) { $this->beConstructedWith($config, $cache); } - function it_is_initializable(Config $config) + public function it_is_initializable(Config $config) { $config->get(Argument::any())->shouldBeCalled(); $this->shouldHaveType('Omniphx\Forrest\Interfaces\StorageInterface'); } - function it_should_allow_a_get(FakeCacheStore $cache) + public function it_should_allow_a_get(FakeCacheStore $cache) { $cache->has(Argument::any())->shouldBeCalled()->willReturn(true); $cache->get(Argument::any())->shouldBeCalled(); @@ -29,7 +28,7 @@ function it_should_allow_a_get(FakeCacheStore $cache) $this->get('test'); } - function it_should_allow_a_put(FakeCacheStore $cache, Config $config) + public function it_should_allow_a_put(FakeCacheStore $cache, Config $config) { $config->get(Argument::any())->shouldBeCalled()->willReturn(10); $cache->put(Argument::any(), Argument::any(), Argument::type('integer'))->shouldBeCalled(); @@ -37,16 +36,24 @@ function it_should_allow_a_put(FakeCacheStore $cache, Config $config) $this->put('test', 'value'); } - function it_should_allow_a_has(FakeCacheStore $cache) + public function it_should_allow_a_has(FakeCacheStore $cache) { $cache->has(Argument::any())->shouldBeCalled(); $this->has('test'); } +} +class FakeCacheStore extends Cache +{ + public function has($str) + { + } + public function get($str) + { + } + + public function put($str) + { + } } -class FakeCacheStore extends Cache { - function has($str) {} - function get($str) {} - function put($str) {} -} \ No newline at end of file diff --git a/spec/Omniphx/Forrest/Providers/Laravel/LaravelEventSpec.php b/spec/Omniphx/Forrest/Providers/Laravel/LaravelEventSpec.php index ebd1ede..fb1a0c2 100644 --- a/spec/Omniphx/Forrest/Providers/Laravel/LaravelEventSpec.php +++ b/spec/Omniphx/Forrest/Providers/Laravel/LaravelEventSpec.php @@ -1,14 +1,13 @@ -shouldHaveType('Omniphx\Forrest\Providers\Laravel\LaravelEvent'); } - } diff --git a/spec/Omniphx/Forrest/Providers/Laravel/LaravelInputSpec.php b/spec/Omniphx/Forrest/Providers/Laravel/LaravelInputSpec.php index ecb9a9c..60e744a 100644 --- a/spec/Omniphx/Forrest/Providers/Laravel/LaravelInputSpec.php +++ b/spec/Omniphx/Forrest/Providers/Laravel/LaravelInputSpec.php @@ -3,15 +3,11 @@ namespace spec\Omniphx\Forrest\Providers\Laravel; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; -use Input; class LaravelInputSpec extends ObjectBehavior { - - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Omniphx\Forrest\Providers\Laravel\LaravelInput'); } - } diff --git a/spec/Omniphx/Forrest/Providers/Laravel/LaravelRedirectSpec.php b/spec/Omniphx/Forrest/Providers/Laravel/LaravelRedirectSpec.php index e267ce6..b6a3e94 100644 --- a/spec/Omniphx/Forrest/Providers/Laravel/LaravelRedirectSpec.php +++ b/spec/Omniphx/Forrest/Providers/Laravel/LaravelRedirectSpec.php @@ -3,11 +3,10 @@ namespace spec\Omniphx\Forrest\Providers\Laravel; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; class LaravelRedirectSpec extends ObjectBehavior { - function it_is_initializable() + public function it_is_initializable() { $this->shouldHaveType('Omniphx\Forrest\Providers\Laravel\LaravelRedirect'); } diff --git a/spec/Omniphx/Forrest/Providers/Laravel/LaravelSessionSpec.php b/spec/Omniphx/Forrest/Providers/Laravel/LaravelSessionSpec.php index 1cc376c..f05e77b 100644 --- a/spec/Omniphx/Forrest/Providers/Laravel/LaravelSessionSpec.php +++ b/spec/Omniphx/Forrest/Providers/Laravel/LaravelSessionSpec.php @@ -2,26 +2,25 @@ namespace spec\Omniphx\Forrest\Providers\Laravel; -use PhpSpec\ObjectBehavior; -use Prophecy\Argument; use Illuminate\Config\Repository as Config; use Illuminate\Session\SessionManager as Session; +use PhpSpec\ObjectBehavior; +use Prophecy\Argument; class LaravelSessionSpec extends ObjectBehavior { - - function let(Config $config, Session $session) + public function let(Config $config, Session $session) { $this->beConstructedWith($config, $session); } - function it_is_initializable(Config $config) + public function it_is_initializable(Config $config) { $config->get(Argument::any())->shouldBeCalled(); $this->shouldHaveType('Omniphx\Forrest\Providers\Laravel\LaravelSession'); } - function it_should_allow_a_get(FakeSessionStore $session) + public function it_should_allow_a_get(FakeSessionStore $session) { $session->has(Argument::any())->shouldBeCalled()->willReturn(true); $session->get(Argument::any())->shouldBeCalled(); @@ -29,24 +28,32 @@ function it_should_allow_a_get(FakeSessionStore $session) $this->get('test'); } - function it_should_allow_a_put(FakeSessionStore $session) + public function it_should_allow_a_put(FakeSessionStore $session) { $session->put(Argument::any(), Argument::any())->shouldBeCalled(); $this->put('test', 'value'); } - function it_should_allow_a_has(FakeSessionStore $session) + public function it_should_allow_a_has(FakeSessionStore $session) { $session->has(Argument::any())->shouldBeCalled(); $this->has('test'); } - } -class FakeSessionStore extends Session { - function has($str) {} - function get($str) {} - function put($str) {} -} \ No newline at end of file +class FakeSessionStore extends Session +{ + public function has($str) + { + } + + public function get($str) + { + } + + public function put($str) + { + } +} diff --git a/src/Omniphx/Forrest/Authentications/UserPassword.php b/src/Omniphx/Forrest/Authentications/UserPassword.php index 907415d..a0053a0 100644 --- a/src/Omniphx/Forrest/Authentications/UserPassword.php +++ b/src/Omniphx/Forrest/Authentications/UserPassword.php @@ -1,31 +1,36 @@ -client = $client; - $this->storage = $storage; - $this->redirect = $redirect; - $this->input = $input; - $this->event = $event; - $this->settings = $settings; + $this->client = $client; + $this->storage = $storage; + $this->redirect = $redirect; + $this->input = $input; + $this->event = $event; + $this->settings = $settings; $this->credentials = $settings['credentials']; } @@ -58,7 +63,7 @@ public function authenticate($loginURL = null) 'password' => $this->credentials['password'], ]; $response = $this->client->post($tokenURL, $parameters); - + // Response returns an json of access_token, instance_url, id, issued_at, and signature. $jsonResponse = $response->json(); @@ -70,12 +75,13 @@ public function authenticate($loginURL = null) } /** - * Refresh authentication token by re-authenticating + * Refresh authentication token by re-authenticating. + * * @return mixed $response */ public function refresh() { - $tokenURL = $this->credentials['loginURL'] . '/services/oauth2/token'; + $tokenURL = $this->credentials['loginURL'].'/services/oauth2/token'; $response = $this->client->post($tokenURL, [ 'body' => [ 'grant_type' => 'password', @@ -83,7 +89,7 @@ public function refresh() 'client_secret' => $this->credentials['consumerSecret'], 'username' => $this->credentials['username'], 'password' => $this->credentials['password'], - ] + ], ]); // Response returns an json of access_token, instance_url, id, issued_at, and signature. @@ -95,23 +101,26 @@ public function refresh() /** * Revokes access token from Salesforce. Will not flush token from storage. + * * @return mixed */ public function revoke() { $accessToken = $this->getTokenData()['access_token']; - $url = $this->credentials['loginURL'] . '/services/oauth2/revoke'; + $url = $this->credentials['loginURL'].'/services/oauth2/revoke'; $options['headers']['content-type'] = 'application/x-www-form-urlencoded'; - $options['body']['token'] = $accessToken; + $options['body']['token'] = $accessToken; return $this->client->post($url, $options); } /** - * Try requesting token, if token expired try refreshing token - * @param string $url - * @param array $options + * Try requesting token, if token expired try refreshing token. + * + * @param string $url + * @param array $options + * * @return mixed */ public function request($url, $options) @@ -120,8 +129,8 @@ public function request($url, $options) return $this->requestResource($url, $options); } catch (TokenExpiredException $e) { $this->refresh(); + return $this->requestResource($url, $options); } } - -} \ No newline at end of file +} diff --git a/src/Omniphx/Forrest/Authentications/WebServer.php b/src/Omniphx/Forrest/Authentications/WebServer.php index 2554717..0e4a437 100644 --- a/src/Omniphx/Forrest/Authentications/WebServer.php +++ b/src/Omniphx/Forrest/Authentications/WebServer.php @@ -1,39 +1,43 @@ -client = $client; - $this->storage = $storage; + $this->client = $client; + $this->storage = $storage; $this->redirect = $redirect; - $this->input = $input; - $this->event = $event; + $this->input = $input; + $this->event = $event; $this->settings = $settings; $this->credentials = $settings['credentials']; $this->parameters = $settings['parameters']; } - /** + /** * Call this method to redirect user to login page and initiate * the Web Server OAuth Authentication Flow. + * * @return void */ public function authenticate($loginURL = null) { - if(!isset($loginURL)){ + if (!isset($loginURL)) { $loginURL = $this->credentials['loginURL']; } $loginURL .= '/services/oauth2/authorize'; $loginURL .= '?response_type=code'; - $loginURL .= '&client_id=' . $this->credentials['consumerKey']; - $loginURL .= '&redirect_uri=' . urlencode($this->credentials['callbackURI']); - if($this->parameters['display'] != ''){ - $loginURL .= '&display=' . $this->parameters['display']; + $loginURL .= '&client_id='.$this->credentials['consumerKey']; + $loginURL .= '&redirect_uri='.urlencode($this->credentials['callbackURI']); + if ($this->parameters['display'] != '') { + $loginURL .= '&display='.$this->parameters['display']; } - if($this->parameters['immediate']){ + if ($this->parameters['immediate']) { $loginURL .= '&immediate=true'; } - if($this->parameters['state'] != ''){ - $loginURL .= '&state=' . urlencode($this->parameters['state']); + if ($this->parameters['state'] != '') { + $loginURL .= '&state='.urlencode($this->parameters['state']); } - if($this->parameters['scope'] != '') { + if ($this->parameters['scope'] != '') { $scope = rawurlencode($this->parameters['scope']); - $loginURL .= '&scope=' . $scope; + $loginURL .= '&scope='.$scope; } - if($this->parameters['prompt'] != '') { + if ($this->parameters['prompt'] != '') { $prompt = rawurlencode($this->parameters['prompt']); - $loginURL .= '&prompt=' . $prompt; + $loginURL .= '&prompt='.$prompt; } return $this->redirect->to($loginURL); @@ -94,24 +99,25 @@ public function authenticate($loginURL = null) /** * When settings up your callback route, you will need to call this method to * acquire an authorization token. This token will be used for the API requests. + * * @return RedirectInterface */ public function callback() { //Salesforce sends us an authorization code as part of the Web Server OAuth Authentication Flow - $code = $this->input->get('code'); + $code = $this->input->get('code'); $state = $this->input->get('state'); //Now we must make a request for the authorization token. - $tokenURL = $this->credentials['loginURL'] . '/services/oauth2/token'; + $tokenURL = $this->credentials['loginURL'].'/services/oauth2/token'; $response = $this->client->post($tokenURL, [ 'body' => [ 'code' => $code, 'grant_type' => 'authorization_code', 'client_id' => $this->credentials['consumerKey'], 'client_secret' => $this->credentials['consumerSecret'], - 'redirect_uri' => $this->credentials['callbackURI'] - ] + 'redirect_uri' => $this->credentials['callbackURI'], + ], ]); // Response returns an json of access_token, instance_url, id, issued_at, and signature. @@ -126,22 +132,24 @@ public function callback() } /** - * Refresh authentication token - * @param Array $refreshToken + * Refresh authentication token. + * + * @param array $refreshToken + * * @return mixed $response */ public function refresh() { $refreshToken = $this->storage->getRefreshToken(); - $tokenURL = $this->credentials['loginURL'] . '/services/oauth2/token'; + $tokenURL = $this->credentials['loginURL'].'/services/oauth2/token'; $response = $this->client->post($tokenURL, [ 'body' => [ 'refresh_token' => $refreshToken, 'grant_type' => 'refresh_token', 'client_id' => $this->credentials['consumerKey'], - 'client_secret' => $this->credentials['consumerSecret'] - ] + 'client_secret' => $this->credentials['consumerSecret'], + ], ]); // Response returns an json of access_token, instance_url, id, issued_at, and signature. @@ -153,23 +161,26 @@ public function refresh() /** * Revokes access token from Salesforce. Will not flush token from storage. + * * @return mixed */ public function revoke() { $accessToken = $this->getTokenData()['access_token']; - $url = $this->credentials['loginURL'] . '/services/oauth2/revoke'; + $url = $this->credentials['loginURL'].'/services/oauth2/revoke'; $options['headers']['content-type'] = 'application/x-www-form-urlencoded'; - $options['body']['token'] = $accessToken; + $options['body']['token'] = $accessToken; return $this->client->post($url, $options); } /** - * Try requesting token, if token expired try refreshing token - * @param string $url - * @param array $options + * Try requesting token, if token expired try refreshing token. + * + * @param string $url + * @param array $options + * * @return mixed */ public function request($url, $options) @@ -178,8 +189,8 @@ public function request($url, $options) return $this->requestResource($url, $options); } catch (TokenExpiredException $e) { $this->refresh(); + return $this->requestResource($url, $options); } } - -} \ No newline at end of file +} diff --git a/src/Omniphx/Forrest/Client.php b/src/Omniphx/Forrest/Client.php index 304b664..20d3002 100644 --- a/src/Omniphx/Forrest/Client.php +++ b/src/Omniphx/Forrest/Client.php @@ -1,43 +1,51 @@ -getInstanceUrl(); $url .= '/'.trim($path, "/\t\n\r\0\x0B"); $options['method'] = 'GET'; - if($requestBody) { + if ($requestBody) { $options['body'] = $requestBody; } @@ -45,17 +53,19 @@ public function get($path, $requestBody = array(), $options = array()) { } /** - * POST method call using any custom path + * POST method call using any custom path. + * * @param string $path - * @param array $requestBody - * @param array $options + * @param array $requestBody + * @param array $options */ - public function post($path, $requestBody = array(), $options = array()) { + public function post($path, $requestBody = [], $options = []) + { $url = $this->getInstanceUrl(); $url .= '/'.trim($path, "/\t\n\r\0\x0B"); $options['method'] = 'POST'; - if($requestBody) { + if ($requestBody) { $options['body'] = $requestBody; } @@ -63,17 +73,19 @@ public function post($path, $requestBody = array(), $options = array()) { } /** - * PUT method call using any custom path + * PUT method call using any custom path. + * * @param string $path - * @param array $requestBody - * @param array $options + * @param array $requestBody + * @param array $options */ - public function put($path, $requestBody = array(), $options = array()) { + public function put($path, $requestBody = [], $options = []) + { $url = $this->getInstanceUrl(); $url .= '/'.trim($path, "/\t\n\r\0\x0B"); $options['method'] = 'PUT'; - if($requestBody) { + if ($requestBody) { $options['body'] = $requestBody; } @@ -81,17 +93,19 @@ public function put($path, $requestBody = array(), $options = array()) { } /** - * DELETE method call using any custom path + * DELETE method call using any custom path. + * * @param string $path - * @param array $requestBody - * @param array $options + * @param array $requestBody + * @param array $options */ - public function delete($path, $requestBody = array(), $options = array()) { + public function delete($path, $requestBody = [], $options = []) + { $url = $this->getInstanceUrl(); $url .= '/'.trim($path, "/\t\n\r\0\x0B"); $options['method'] = 'DELETE'; - if($requestBody) { + if ($requestBody) { $options['body'] = $requestBody; } @@ -99,17 +113,19 @@ public function delete($path, $requestBody = array(), $options = array()) { } /** - * HEAD method call using any custom path + * HEAD method call using any custom path. + * * @param string $path - * @param array $requestBody - * @param array $options + * @param array $requestBody + * @param array $options */ - public function head($path, $requestBody = array(), $options = array()) { + public function head($path, $requestBody = [], $options = []) + { $url = $this->getInstanceUrl(); $url .= '/'.trim($path, "/\t\n\r\0\x0B"); $options['method'] = 'HEAD'; - if($requestBody) { + if ($requestBody) { $options['body'] = $requestBody; } @@ -117,17 +133,19 @@ public function head($path, $requestBody = array(), $options = array()) { } /** - * PATCH method call using any custom path + * PATCH method call using any custom path. + * * @param string $path - * @param array $requestBody - * @param array $options + * @param array $requestBody + * @param array $options */ - public function patch($path, $requestBody = array(), $options = array()) { + public function patch($path, $requestBody = [], $options = []) + { $url = $this->getInstanceUrl(); $url .= '/'.trim($path, "/\t\n\r\0\x0B"); $options['method'] = 'PATCH'; - if($requestBody) { + if ($requestBody) { $options['body'] = $requestBody; } @@ -138,8 +156,10 @@ public function patch($path, $requestBody = array(), $options = array()) { * Request that returns all currently supported versions. * Includes the verison, label and link to each version's root. * Formats: json, xml - * Methods: get - * @param array $options + * Methods: get. + * + * @param array $options + * * @return array $versions */ public function versions($options = []) @@ -156,8 +176,10 @@ public function versions($options = []) * Lists availabe resources for specified API version. * Includes resource name and URI. * Formats: json, xml - * Methods: get - * @param array $options + * Methods: get. + * + * @param array $options + * * @return array $resources */ public function resources($options = []) @@ -172,14 +194,16 @@ public function resources($options = []) /** * Returns information about the logged-in user. + * * @param array + * * @return array $identity */ - public function identity($options =[]) + public function identity($options = []) { - $token = $this->getTokenData(); + $token = $this->getTokenData(); $accessToken = $token['access_token']; - $url = $token['id']; + $url = $token['id']; $options['headers']['Authorization'] = "OAuth $accessToken"; @@ -192,10 +216,12 @@ public function identity($options =[]) * Lists information about organizational limits. * Available for API version 29.0 and later. * Returns limits for daily API calls, Data storage, etc. - * @param array $options + * + * @param array $options + * * @return array $limits */ - public function limits($options =[]) + public function limits($options = []) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('version')['url']; @@ -208,9 +234,10 @@ public function limits($options =[]) /** * Describes all global objects availabe in the organization. + * * @return array */ - public function describe($options =[]) + public function describe($options = []) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('version')['url']; @@ -223,8 +250,10 @@ public function describe($options =[]) /** * Executes a specified SOQL query. - * @param string $query - * @param array $options + * + * @param string $query + * @param array $options + * * @return array $queryResults */ public function query($query, $options = []) @@ -238,9 +267,10 @@ public function query($query, $options = []) return $queryResults; } - + /** - * Calls next query + * Calls next query. + * * @param $nextUrl * @param array $options * @@ -258,9 +288,11 @@ public function next($nextUrl, $options = []) /** * Details how Salesforce will process your query. - * Available for API verison 30.0 or later - * @param string $query - * @param array $options + * Available for API verison 30.0 or later. + * + * @param string $query + * @param array $options + * * @return array $queryExplain */ public function queryExplain($query, $options = []) @@ -278,12 +310,14 @@ public function queryExplain($query, $options = []) /** * Executes a SOQL query, but will also returned records that have * been deleted. - * Available for API version 29.0 or later - * @param string $query - * @param array $options + * Available for API version 29.0 or later. + * + * @param string $query + * @param array $options + * * @return array $queryResults */ - public function queryAll($query,$options = []) + public function queryAll($query, $options = []) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('resources')['queryAll']; @@ -296,12 +330,14 @@ public function queryAll($query,$options = []) } /** - * Executes the specified SOSL query - * @param string $query - * @param array $options + * Executes the specified SOSL query. + * + * @param string $query + * @param array $options + * * @return array */ - public function search($query,$options = []) + public function search($query, $options = []) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('resources')['search']; @@ -319,7 +355,9 @@ public function search($query,$options = []) * objects the user interacts with and how often and arranges the * search results accordingly. Objects used most frequently appear * at the top of the list. - * @param array $options + * + * @param array $options + * * @return array */ public function scopeOrder($options = []) @@ -335,11 +373,13 @@ public function scopeOrder($options = []) /** * Returns search result layout information for the objects in the query string. - * @param array $objectList - * @param array $options + * + * @param array $objectList + * @param array $options + * * @return array */ - public function searchLayouts($objectList,$options = []) + public function searchLayouts($objectList, $options = []) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('resources')['search']; @@ -355,13 +395,15 @@ public function searchLayouts($objectList,$options = []) * Returns a list of Salesforce Knowledge articles whose titles match the user’s * search query. Provides a shortcut to navigate directly to likely * relevant articles, before the user performs a search. - * Available for API version 30.0 or later - * @param string $query - * @param array $searchParameters - * @param array $option + * Available for API version 30.0 or later. + * + * @param string $query + * @param array $searchParameters + * @param array $option + * * @return array */ - public function suggestedArticles($query,$options = []) + public function suggestedArticles($query, $options = []) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('resources')['search']; @@ -370,11 +412,11 @@ public function suggestedArticles($query,$options = []) $parameters = [ 'language' => $this->settings['language'], - 'publishStatus' => 'Online']; + 'publishStatus' => 'Online', ]; if (isset($options['parameters'])) { $parameters = array_replace_recursive($parameters, $options['parameters']); - $url .= '&' . http_build_query($parameters); + $url .= '&'.http_build_query($parameters); } $suggestedArticles = $this->request($url, $options); @@ -389,11 +431,12 @@ public function suggestedArticles($query,$options = []) * * Tested this and can't get it to work. I think the request is set up correctly. * - * @param string $query - * @param array $options + * @param string $query + * @param array $options + * * @return array */ - public function suggestedQueries($query,$options = []) + public function suggestedQueries($query, $options = []) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('resources')['search']; @@ -404,7 +447,7 @@ public function suggestedQueries($query,$options = []) if (isset($options['parameters'])) { $parameters = array_replace_recursive($parameters, $options['parameters']); - $url .= '&' . http_build_query($parameters); + $url .= '&'.http_build_query($parameters); } $suggestedQueries = $this->request($url, $options); @@ -413,9 +456,11 @@ public function suggestedQueries($query,$options = []) } /** - * Request to a custom Apex REST endpoint - * @param String $customURI - * @param Array $option + * Request to a custom Apex REST endpoint. + * + * @param string $customURI + * @param array $option + * * @return mixed */ public function custom($customURI, $options = []) @@ -428,14 +473,14 @@ public function custom($customURI, $options = []) if (isset($options['parameters'])) { $parameters = array_replace_recursive($parameters, $options['parameters']); - $url .= '?' . http_build_query($parameters); + $url .= '?'.http_build_query($parameters); } return $this->request($url, $options); } /** - * Public accessor to the Guzzle Client Object + * Public accessor to the Guzzle Client Object. * * @return GuzzleHttp\ClientInterface */ @@ -449,11 +494,13 @@ public function getClient() * user. Reference Force.com's REST API guide to read about more * methods that can be called or refence them by calling the * Session::get('resources') method. - * @param string $name - * @param array $arguments + * + * @param string $name + * @param array $arguments + * * @return array */ - public function __call($name,$arguments) + public function __call($name, $arguments) { $url = $this->getInstanceUrl(); $url .= $this->storage->get('resources')[$name]; @@ -463,8 +510,7 @@ public function __call($name,$arguments) if (isset($arguments[0])) { if (is_string($arguments[0])) { $url .= "/$arguments[0]"; - } - else if (is_array($arguments[0])){ + } elseif (is_array($arguments[0])) { foreach ($arguments[0] as $key => $value) { $options[$key] = $value; } @@ -483,7 +529,8 @@ public function __call($name,$arguments) } /** - * Get token + * Get token. + * * @return array */ public function getTokenData() @@ -492,15 +539,16 @@ public function getTokenData() } /** - * Get the instance URL + * Get the instance URL. + * * @return string */ protected function getInstanceUrl() { $url = $this->settings['instanceURL']; - if (empty($url)){ - $url = $this->getTokenData()['instance_url']; + if (empty($url)) { + $url = $this->getTokenData()['instance_url']; } return $url; @@ -511,22 +559,22 @@ protected function getInstanceUrl() * assign the latest version number available to the user's instance. * Once a version number is determined, it will be stored in the user's * storage with the 'version' key. + * * @return void */ protected function storeVersion() { $configVersion = $this->settings['version']; - if ($configVersion != null){ - $versions = $this->versions(['format'=>'json']); + if ($configVersion != null) { + $versions = $this->versions(['format' => 'json']); foreach ($versions as $version) { - if ($version['version'] == $configVersion){ - $this->storage->put('version',$version); + if ($version['version'] == $configVersion) { + $this->storage->put('version', $version); } } - } - else { - $versions = $this->versions(['format'=>'json']); + } else { + $versions = $this->versions(['format' => 'json']); $latestVersion = end($versions); $this->storage->put('version', $latestVersion); } @@ -536,26 +584,28 @@ protected function storeVersion() * Checks to see if version is specified. If not then call storeVersion. * Once a version is determined, determine the available resources the * user has access to and store them in teh user's sesion. + * * @return void */ protected function storeResources() { try { $version = $this->storage->get('version'); - $resources = $this->resources(['format'=>'json']); + $resources = $this->resources(['format' => 'json']); $this->storage->put('resources', $resources); - } - catch (\Exception $e) { + } catch (\Exception $e) { $this->storeVersion(); - $resources = $this->resources(['format'=>'json']); + $resources = $this->resources(['format' => 'json']); $this->storage->put('resources', $resources); } } /** - * Method returns the response for the requested resource - * @param string $pURI - * @param array $pOptions + * Method returns the response for the requested resource. + * + * @param string $pURI + * @param array $pOptions + * * @return mixed */ protected function requestResource($pURL, array $pOptions) @@ -573,25 +623,24 @@ protected function requestResource($pURL, array $pOptions) $parameters['body'] = $this->formatBody($options); } - $request = $this->client->createRequest($method,$pURL,$parameters); + $request = $this->client->createRequest($method, $pURL, $parameters); try { $response = $this->client->send($request); - $this->event->fire('forrest.response', array($request, $response)); + $this->event->fire('forrest.response', [$request, $response]); return $this->responseFormat($response, $format); - - } catch(RequestException $e) { + } catch (RequestException $e) { $this->assignExceptions($e); } - - } /** - * Set the headers for the request + * Set the headers for the request. + * * @param array $options + * * @return array $headers */ private function setHeaders(array $options) @@ -601,7 +650,7 @@ private function setHeaders(array $options) $authToken = $this->storage->getTokenData(); $accessToken = $authToken['access_token']; - $tokenType = $authToken['token_type']; + $tokenType = $authToken['token_type']; $this->headers['Authorization'] = "$tokenType $accessToken"; @@ -610,19 +659,20 @@ private function setHeaders(array $options) } /** - * Format the body for the request + * Format the body for the request. + * * @param array $options + * * @return array $body */ private function formatBody(array $options) { $format = $options['format']; - $data = $options['body']; + $data = $options['body']; if ($format == 'json') { $body = json_encode($data); - } - else if($format == 'xml') { + } elseif ($format == 'xml') { $body = urlencode($data); } @@ -630,17 +680,16 @@ private function formatBody(array $options) } //Need to think through this for it to work + private function setRequestFormat($format) { if ($format == 'json') { $this->headers['Accept'] = 'application/json'; $this->headers['Content-Type'] = 'application/json'; - } - else if ($format == 'xml') { + } elseif ($format == 'xml') { $this->headers['Accept'] = 'application/xml'; $this->headers['Content-Type'] = 'application/xml'; - } - else if ($format == 'urlencoded') { + } elseif ($format == 'urlencoded') { $this->headers['Accept'] = 'application/x-www-form-urlencoded'; $this->headers['Content-Type'] = 'application/x-www-form-urlencoded'; } @@ -655,17 +704,18 @@ private function setCompression($options) } /** - * Returns the response in the configured format - * @param Response $response - * @param string $format + * Returns the response in the configured format. + * + * @param Response $response + * @param string $format + * * @return mixed $response */ - private function responseFormat($response,$format) + private function responseFormat($response, $format) { if ($format == 'json') { return $response->json(); - } - else if ($format == 'xml') { + } elseif ($format == 'xml') { return $response->xml(); } @@ -673,19 +723,20 @@ private function responseFormat($response,$format) } /** - * Method will elaborate on RequestException - * @param GuzzleHttp\Exception\ClientException $e + * Method will elaborate on RequestException. + * + * @param GuzzleHttp\Exception\ClientException $e + * * @return mixed */ private function assignExceptions($e) { if ($e->hasResponse() && $e->getResponse()->getStatusCode() == '401') { - throw new TokenExpiredException(sprintf("Salesforce token has expired")); - } else if($e->hasResponse()){ - throw new SalesforceException(sprintf("Salesforce response error: %s",$e->getResponse())); + throw new TokenExpiredException(sprintf('Salesforce token has expired')); + } elseif ($e->hasResponse()) { + throw new SalesforceException(sprintf('Salesforce response error: %s', $e->getResponse())); } else { - throw new SalesforceException(sprintf("Invalid request: %s",$e->getRequest())); + throw new SalesforceException(sprintf('Invalid request: %s', $e->getRequest())); } } - } diff --git a/src/Omniphx/Forrest/Exceptions/MissingKeyException.php b/src/Omniphx/Forrest/Exceptions/MissingKeyException.php index d21f652..67eb5b5 100644 --- a/src/Omniphx/Forrest/Exceptions/MissingKeyException.php +++ b/src/Omniphx/Forrest/Exceptions/MissingKeyException.php @@ -1,3 +1,7 @@ -publishes([ - __DIR__.'/../../../../config/config.php' => config_path('forrest.php'), - ]); +class ForrestServiceProvider extends ServiceProvider +{ + /** + * Indicates if loading of the provider is deferred. + * + * @var bool + */ + protected $defer = false; - $authentication = config('forrest.authentication'); + /** + * Bootstrap the application events. + * + * @return void + */ + public function boot() + { + $this->publishes([ + __DIR__.'/../../../../config/config.php' => config_path('forrest.php'), + ]); - if(!is_null($authentication)){ - include __DIR__ . "/Routes/$authentication.php"; - } - } + $authentication = config('forrest.authentication'); - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->bindShared('forrest', function($app){ + if (!is_null($authentication)) { + include __DIR__."/Routes/$authentication.php"; + } + } - //Config options: - $settings = config('forrest'); - $authenticationType = config('forrest.authentication'); - $storageType = config('forrest.storage.type'); + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->app->bindShared('forrest', function ($app) { - //Dependencies: - $client = new \GuzzleHttp\Client(); - $input = new \Omniphx\Forrest\Providers\Laravel\LaravelInput(); - $event = new \Omniphx\Forrest\Providers\Laravel\LaravelEvent(); - $redirect = new \Omniphx\Forrest\Providers\Laravel\LaravelRedirect(); + //Config options: + $settings = config('forrest'); + $authenticationType = config('forrest.authentication'); + $storageType = config('forrest.storage.type'); - //Determine storage dependency: - if($storageType == 'cache') { - $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelCache(app('config'), app('cache')); - } else { - $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelSession(app('config'), app('session')); - } + //Dependencies: + $client = new \GuzzleHttp\Client(); + $input = new \Omniphx\Forrest\Providers\Laravel\LaravelInput(); + $event = new \Omniphx\Forrest\Providers\Laravel\LaravelEvent(); + $redirect = new \Omniphx\Forrest\Providers\Laravel\LaravelRedirect(); - //Class namespace: - $forrest = "\\Omniphx\\Forrest\\Authentications\\$authenticationType"; + //Determine storage dependency: + if ($storageType == 'cache') { + $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelCache(app('config'), app('cache')); + } else { + $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelSession(app('config'), app('session')); + } - return new $forrest($client, $storage, $redirect, $input, $event, $settings); + //Class namespace: + $forrest = "\\Omniphx\\Forrest\\Authentications\\$authenticationType"; - }); - } + return new $forrest($client, $storage, $redirect, $input, $event, $settings); - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return array(); - } + }); + } -} \ No newline at end of file + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return []; + } +} diff --git a/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php b/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php index 238f49e..982f156 100644 --- a/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php +++ b/src/Omniphx/Forrest/Providers/Laravel/LaravelCache.php @@ -1,62 +1,69 @@ -path = $config->get('forrest.storage.path'); + + $this->cache = $cache; + + if ($minutes = $config->get('forrest.storage.expire_in')) { + $this->minutes = $minutes; + } + } + + /** + * Store into session. + * + * @param $key + * @param $value + * + * @return void + */ + public function put($key, $value) + { + return $this->cache->put($this->path.$key, $value, $this->minutes); + } + + /** + * Get from session. + * + * @param $key + * + * @return mixed + */ + public function get($key) + { + if ($this->cache->has($this->path.$key)) { + return $this->cache->get($this->path.$key); + } -class LaravelCache extends LaravelStorageProvider implements StorageInterface { - - public $minutes = 20; - - public $path; - - protected $cache; - - public function __construct(Config $config, Cache $cache) - { - $this->path = $config->get('forrest.storage.path'); - - $this->cache = $cache; - - if($minutes = $config->get('forrest.storage.expire_in')) { - $this->minutes = $minutes; - } - } - - /** - * Store into session. - * @param $key - * @param $value - * @return void - */ - public function put($key, $value) - { - return $this->cache->put($this->path.$key, $value, $this->minutes); - } - - /** - * Get from session - * @param $key - * @return mixed - */ - public function get($key) - { - if ($this->cache->has($this->path.$key)) { - return $this->cache->get($this->path.$key); - } - - throw new MissingKeyException(sprintf("No value for requested key: %s",$key)); - } - - /** - * Check if storage has a key - * @param $key - * @return boolean - */ - public function has($key) - { - return $this->cache->has($this->path.$key); - } + throw new MissingKeyException(sprintf('No value for requested key: %s', $key)); + } + /** + * Check if storage has a key. + * + * @param $key + * + * @return bool + */ + public function has($key) + { + return $this->cache->has($this->path.$key); + } } diff --git a/src/Omniphx/Forrest/Providers/Laravel/LaravelEvent.php b/src/Omniphx/Forrest/Providers/Laravel/LaravelEvent.php index cf7596d..4830ca2 100644 --- a/src/Omniphx/Forrest/Providers/Laravel/LaravelEvent.php +++ b/src/Omniphx/Forrest/Providers/Laravel/LaravelEvent.php @@ -1,19 +1,23 @@ -path = $config->get('forrest.storage.path'); - - $this->session = $session; - } - - /** - * Store into session. - * @param $key - * @param $value - * @return void - */ - public function put($key, $value) - { - return $this->session->put($this->path.$key, $value); - } - - /** - * Get from session - * @param $key - * @return mixed - */ - public function get($key) - { - if ($this->session->has($this->path.$key)) { - return $this->session->get($this->path.$key); - } - - throw new MissingKeyException(sprintf("No value for requested key: %s",$key)); - } - - /** - * Check if storage has a key - * @param $key - * @return boolean - */ - public function has($key) - { - return $this->session->has($this->path.$key); - } - +class LaravelSession extends LaravelStorageProvider implements StorageInterface +{ + public $path; + + protected $session; + + public function __construct(Config $config, Session $session) + { + $this->path = $config->get('forrest.storage.path'); + + $this->session = $session; + } + + /** + * Store into session. + * + * @param $key + * @param $value + * + * @return void + */ + public function put($key, $value) + { + return $this->session->put($this->path.$key, $value); + } + + /** + * Get from session. + * + * @param $key + * + * @return mixed + */ + public function get($key) + { + if ($this->session->has($this->path.$key)) { + return $this->session->get($this->path.$key); + } + + throw new MissingKeyException(sprintf('No value for requested key: %s', $key)); + } + + /** + * Check if storage has a key. + * + * @param $key + * + * @return bool + */ + public function has($key) + { + return $this->session->has($this->path.$key); + } } diff --git a/src/Omniphx/Forrest/Providers/Laravel/LaravelStorageProvider.php b/src/Omniphx/Forrest/Providers/Laravel/LaravelStorageProvider.php index 229e5ce..39678c7 100644 --- a/src/Omniphx/Forrest/Providers/Laravel/LaravelStorageProvider.php +++ b/src/Omniphx/Forrest/Providers/Laravel/LaravelStorageProvider.php @@ -1,31 +1,38 @@ -put('token', $encryptedToken); } /** * Get token from the session and decrypt it. + * * @return mixed */ public function getTokenData() { if ($this->has('token')) { $token = $this->get('token'); + return Crypt::decrypt($token); } @@ -34,23 +41,28 @@ public function getTokenData() /** * Encrypt refresh token and pass into session. - * @param Array $token + * + * @param array $token + * * @return void */ public function putRefreshToken($token) { $encryptedToken = Crypt::encrypt($token); + return $this->put('refresh_token', $encryptedToken); } /** * Get refresh token from session and decrypt it. + * * @return mixed */ public function getRefreshToken() { if ($this->has('refresh_token')) { $token = $this->get('refresh_token'); + return Crypt::decrypt($token); } diff --git a/src/Omniphx/Forrest/Providers/Laravel/Routes/UserPassword.php b/src/Omniphx/Forrest/Providers/Laravel/Routes/UserPassword.php index 8a01cc5..c2a64c7 100644 --- a/src/Omniphx/Forrest/Providers/Laravel/Routes/UserPassword.php +++ b/src/Omniphx/Forrest/Providers/Laravel/Routes/UserPassword.php @@ -9,11 +9,10 @@ | */ -Route::get('/authenticate', function() -{ +Route::get('/authenticate', function () { Forrest::authenticate(); $url = Config::get('forrest.authRedirect'); return Redirect::to($url); -}); \ No newline at end of file +}); diff --git a/src/Omniphx/Forrest/Providers/Laravel/Routes/WebServer.php b/src/Omniphx/Forrest/Providers/Laravel/Routes/WebServer.php index 01cf7b9..ec5e247 100644 --- a/src/Omniphx/Forrest/Providers/Laravel/Routes/WebServer.php +++ b/src/Omniphx/Forrest/Providers/Laravel/Routes/WebServer.php @@ -9,16 +9,14 @@ | */ -Route::get('/authenticate', function() -{ +Route::get('/authenticate', function () { return Forrest::authenticate(); }); -Route::get('/callback', function() -{ +Route::get('/callback', function () { Forrest::callback(); $url = Config::get('forrest.authRedirect'); return Redirect::to($url); -}); \ No newline at end of file +}); diff --git a/src/Omniphx/Forrest/Providers/Laravel4/Facades/Forrest.php b/src/Omniphx/Forrest/Providers/Laravel4/Facades/Forrest.php index 2790183..4aa10ff 100644 --- a/src/Omniphx/Forrest/Providers/Laravel4/Facades/Forrest.php +++ b/src/Omniphx/Forrest/Providers/Laravel4/Facades/Forrest.php @@ -1,14 +1,18 @@ -package('omniphx/forrest', null, __DIR__.'/../../../..'); - $authentication = Config::get('forrest::authentication'); + $authentication = Config::get('forrest::authentication'); - include __DIR__ . "/../Laravel4/Routes/$authentication.php"; + include __DIR__."/../Laravel4/Routes/$authentication.php"; } /** @@ -33,20 +35,18 @@ public function boot() */ public function register() { + $this->app['forrest'] = $this->app->share(function ($app) { + $settings = Config::get('forrest::config'); - $this->app['forrest'] = $this->app->share(function($app) - { - $settings = Config::get('forrest::config'); - - $client = new \GuzzleHttp\Client(); + $client = new \GuzzleHttp\Client(); $redirect = new \Omniphx\Forrest\Providers\Laravel4\LaravelRedirect(); - if($settings['storage']['type'] == 'cache') { - $storage = new \Omniphx\Forrest\Providers\Laravel4\LaravelCache(app('config'), app('cache')); + if ($settings['storage']['type'] == 'cache') { + $storage = new \Omniphx\Forrest\Providers\Laravel4\LaravelCache(app('config'), app('cache')); } else { - $storage = new \Omniphx\Forrest\Providers\Laravel4\LaravelSession(app('config'), app('session')); + $storage = new \Omniphx\Forrest\Providers\Laravel4\LaravelSession(app('config'), app('session')); } - $input = new \Omniphx\Forrest\Providers\Laravel4\LaravelInput(); - $event = new \Omniphx\Forrest\Providers\Laravel4\LaravelEvent(); + $input = new \Omniphx\Forrest\Providers\Laravel4\LaravelInput(); + $event = new \Omniphx\Forrest\Providers\Laravel4\LaravelEvent(); $authentication = '\\Omniphx\\Forrest\\Authentications\\'; $authentication .= $settings['authentication']; @@ -62,7 +62,6 @@ public function register() */ public function provides() { - return array(); + return []; } - -} \ No newline at end of file +} diff --git a/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php b/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php index 536927a..17fedf0 100644 --- a/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php +++ b/src/Omniphx/Forrest/Providers/Laravel4/LaravelCache.php @@ -1,62 +1,69 @@ -path = $config->get('forrest::config.storage.path'); + + $this->cache = $cache; + + if ($minutes = $config->get('forrest::config.storage.expire_in')) { + $this->minutes = $minutes; + } + } + + /** + * Store into session. + * + * @param $key + * @param $value + * + * @return void + */ + public function put($key, $value) + { + return $this->cache->put($this->path.$key, $value, $this->minutes); + } + + /** + * Get from session. + * + * @param $key + * + * @return mixed + */ + public function get($key) + { + if ($this->cache->has($this->path.$key)) { + return $this->cache->get($this->path.$key); + } -class LaravelCache extends LaravelStorageProvider implements StorageInterface { - - public $minutes = 20; - - public $path; - - protected $cache; - - public function __construct(Config $config, Cache $cache) - { - $this->path = $config->get('forrest::config.storage.path'); - - $this->cache = $cache; - - if($minutes = $config->get('forrest::config.storage.expire_in')) { - $this->minutes = $minutes; - } - } - - /** - * Store into session. - * @param $key - * @param $value - * @return void - */ - public function put($key, $value) - { - return $this->cache->put($this->path.$key, $value, $this->minutes); - } - - /** - * Get from session - * @param $key - * @return mixed - */ - public function get($key) - { - if ($this->cache->has($this->path.$key)) { - return $this->cache->get($this->path.$key); - } - - throw new MissingKeyException(sprintf("No value for requested key: %s",$key)); - } - - /** - * Check if storage has a key - * @param $key - * @return boolean - */ - public function has($key) - { - return $this->cache->has($this->path.$key); - } + throw new MissingKeyException(sprintf('No value for requested key: %s', $key)); + } + /** + * Check if storage has a key. + * + * @param $key + * + * @return bool + */ + public function has($key) + { + return $this->cache->has($this->path.$key); + } } diff --git a/src/Omniphx/Forrest/Providers/Laravel4/LaravelEvent.php b/src/Omniphx/Forrest/Providers/Laravel4/LaravelEvent.php index e138205..ec5a740 100644 --- a/src/Omniphx/Forrest/Providers/Laravel4/LaravelEvent.php +++ b/src/Omniphx/Forrest/Providers/Laravel4/LaravelEvent.php @@ -1,19 +1,23 @@ -path = $config->get('forrest::config.storage.path'); - - $this->session = $session; - } - - /** - * Store into session. - * @param $key - * @param $value - * @return void - */ - public function put($key, $value) - { - return $this->session->put($this->path.$key, $value); - } - - /** - * Get from session - * @param $key - * @return mixed - */ - public function get($key) - { - if ($this->session->has($this->path.$key)) { - return $this->session->get($this->path.$key); - } - - throw new MissingKeyException(sprintf("No value for requested key: %s",$key)); - } - - /** - * Check if storage has a key - * @param $key - * @return boolean - */ - public function has($key) - { - return $this->session->has($this->path.$key); - } - -} \ No newline at end of file +class LaravelSession extends LaravelStorageProvider implements StorageInterface +{ + public $path; + + protected $session; + + public function __construct(Config $config, Session $session) + { + $this->path = $config->get('forrest::config.storage.path'); + + $this->session = $session; + } + + /** + * Store into session. + * + * @param $key + * @param $value + * + * @return void + */ + public function put($key, $value) + { + return $this->session->put($this->path.$key, $value); + } + + /** + * Get from session. + * + * @param $key + * + * @return mixed + */ + public function get($key) + { + if ($this->session->has($this->path.$key)) { + return $this->session->get($this->path.$key); + } + + throw new MissingKeyException(sprintf('No value for requested key: %s', $key)); + } + + /** + * Check if storage has a key. + * + * @param $key + * + * @return bool + */ + public function has($key) + { + return $this->session->has($this->path.$key); + } +} diff --git a/src/Omniphx/Forrest/Providers/Laravel4/LaravelStorageProvider.php b/src/Omniphx/Forrest/Providers/Laravel4/LaravelStorageProvider.php index c51692e..c92db60 100644 --- a/src/Omniphx/Forrest/Providers/Laravel4/LaravelStorageProvider.php +++ b/src/Omniphx/Forrest/Providers/Laravel4/LaravelStorageProvider.php @@ -1,31 +1,38 @@ -put('token', $encryptedToken); } /** * Get token from the session and decrypt it. + * * @return mixed */ public function getTokenData() { if ($this->has('token')) { $token = $this->get('token'); + return Crypt::decrypt($token); } @@ -34,26 +41,31 @@ public function getTokenData() /** * Encrypt refresh token and pass into session. - * @param Array $token + * + * @param array $token + * * @return void */ public function putRefreshToken($token) { $encryptedToken = Crypt::encrypt($token); + return $this->put('refresh_token', $encryptedToken); } /** * Get refresh token from session and decrypt it. + * * @return mixed */ public function getRefreshToken() { if ($this->has('refresh_token')) { $token = $this->get('refresh_token'); + return Crypt::decrypt($token); } throw new MissingRefreshTokenException(sprintf('No refresh token stored in current session. Verify you have added refresh_token to your scope items on your connected app settings in Salesforce.')); } -} \ No newline at end of file +} diff --git a/src/Omniphx/Forrest/Providers/Laravel4/Routes/UserPassword.php b/src/Omniphx/Forrest/Providers/Laravel4/Routes/UserPassword.php index e6b3b43..51b82d5 100644 --- a/src/Omniphx/Forrest/Providers/Laravel4/Routes/UserPassword.php +++ b/src/Omniphx/Forrest/Providers/Laravel4/Routes/UserPassword.php @@ -9,11 +9,10 @@ | */ -Route::get('/authenticate', function() -{ +Route::get('/authenticate', function () { Forrest::authenticate(); $url = Config::get('forrest::authRedirect'); return Redirect::to($url); -}); \ No newline at end of file +}); diff --git a/src/Omniphx/Forrest/Providers/Laravel4/Routes/WebServer.php b/src/Omniphx/Forrest/Providers/Laravel4/Routes/WebServer.php index 20ad691..ac2006a 100644 --- a/src/Omniphx/Forrest/Providers/Laravel4/Routes/WebServer.php +++ b/src/Omniphx/Forrest/Providers/Laravel4/Routes/WebServer.php @@ -9,16 +9,14 @@ | */ -Route::get('/authenticate', function() -{ +Route::get('/authenticate', function () { return Forrest::authenticate(); }); -Route::get('/callback', function() -{ +Route::get('/callback', function () { Forrest::callback(); $url = Config::get('forrest::authRedirect'); return Redirect::to($url); -}); \ No newline at end of file +}); diff --git a/src/Omniphx/Forrest/Providers/Lumen/ForrestServiceProvider.php b/src/Omniphx/Forrest/Providers/Lumen/ForrestServiceProvider.php index 2c0cafd..4e4d826 100644 --- a/src/Omniphx/Forrest/Providers/Lumen/ForrestServiceProvider.php +++ b/src/Omniphx/Forrest/Providers/Lumen/ForrestServiceProvider.php @@ -1,9 +1,11 @@ -publishes([ - __DIR__.'/../../../../config/config.php' => $this->configPath() + __DIR__.'/../../../../config/config.php' => $this->configPath(), ]); $authentication = config('forrest.authentication'); - if(!is_null($authentication)){ - include __DIR__ . "/Routes/$authentication.php"; + if (!is_null($authentication)) { + include __DIR__."/Routes/$authentication.php"; } } @@ -36,24 +38,24 @@ public function boot() */ public function register() { - $this->app->bindShared('forrest', function($app){ + $this->app->bindShared('forrest', function ($app) { //Config options: - $settings = config('forrest'); + $settings = config('forrest'); $authenticationType = config('forrest.authentication'); - $storageType = config('forrest.storage.type'); + $storageType = config('forrest.storage.type'); //Dependencies: - $client = new \GuzzleHttp\Client(); - $input = new \Omniphx\Forrest\Providers\Laravel\LaravelInput(); - $event = new \Omniphx\Forrest\Providers\Laravel\LaravelEvent(); + $client = new \GuzzleHttp\Client(); + $input = new \Omniphx\Forrest\Providers\Laravel\LaravelInput(); + $event = new \Omniphx\Forrest\Providers\Laravel\LaravelEvent(); $redirect = new \Omniphx\Forrest\Providers\Laravel\LaravelRedirect(); //Determine storage dependency: - if($storageType == 'cache') { - $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelCache(app('config'), app('cache')); + if ($storageType == 'cache') { + $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelCache(app('config'), app('cache')); } else { - $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelSession(app('config'), app('session')); + $storage = new \Omniphx\Forrest\Providers\Laravel\LaravelSession(app('config'), app('session')); } //Class namespace: @@ -71,11 +73,11 @@ public function register() */ public function provides() { - return array(); + return []; } protected function configPath() { - return __DIR__ . '/../config/forrest.php'; + return __DIR__.'/../config/forrest.php'; } } diff --git a/src/config/config.php b/src/config/config.php index 03b50c2..b7082ba 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -1,87 +1,88 @@ - 'WebServer', + /* + * Options include WebServer or UserPassword + */ + 'authentication' => 'WebServer', - /** - * Enter your credentials - * Username and Password are only necessary for UserPassword flow. + /* + * Enter your credentials + * Username and Password are only necessary for UserPassword flow. * Likewise, callbackURI is only necessary for WebServer flow. - */ - 'credentials' => array( - //Required: - 'consumerKey' => '', - 'consumerSecret' => '', - 'callbackURI' => '', - 'loginURL' => 'https://login.salesforce.com', + */ + 'credentials' => [ + //Required: + 'consumerKey' => '', + 'consumerSecret' => '', + 'callbackURI' => '', + 'loginURL' => 'https://login.salesforce.com', - // Only required for UserPassword authentication: - 'username' => '', - // Security token might need to be ammended to password unless IP Address is whitelisted - 'password' => '', + // Only required for UserPassword authentication: + 'username' => '', + // Security token might need to be ammended to password unless IP Address is whitelisted + 'password' => '', - ), + ], - /** - * These are optional authentication parameters that can be specified for the WebServer flow. - * https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_web_server_flow.htm&language=en_US - */ - 'parameters' => array( - 'display' => '', - 'immediate' => false, - 'state' => '', - 'scope' => '', - 'prompt' => '', - ), + /* + * These are optional authentication parameters that can be specified for the WebServer flow. + * https://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_web_server_flow.htm&language=en_US + */ + 'parameters' => [ + 'display' => '', + 'immediate' => false, + 'state' => '', + 'scope' => '', + 'prompt' => '', + ], - /** - * Default settings for resource requests. - * Format can be 'json', 'xml' or 'none' - * Compression can be set to 'gzip' or 'deflate' - */ - 'defaults' => array( - 'method' => 'get', - 'format' => 'json', - 'compression' => false, - 'compressionType' => 'gzip', - ), + /* + * Default settings for resource requests. + * Format can be 'json', 'xml' or 'none' + * Compression can be set to 'gzip' or 'deflate' + */ + 'defaults' => [ + 'method' => 'get', + 'format' => 'json', + 'compression' => false, + 'compressionType' => 'gzip', + ], - /** - * Where do you want to store access tokens fetched from Salesforce - */ - 'storage' => array( - 'type' => 'session', // 'session' or 'cache' are the two options - 'path' => 'forrest_', // unique storage path to avoid collisions - 'expire_in' => 60, // number of minutes to expire cache/session - ), + /* + * Where do you want to store access tokens fetched from Salesforce + */ + 'storage' => [ + 'type' => 'session', // 'session' or 'cache' are the two options + 'path' => 'forrest_', // unique storage path to avoid collisions + 'expire_in' => 60, // number of minutes to expire cache/session + ], - /** - * If you'd like to specify an API version manually it can be done here. - * Format looks like '32.0' - */ - 'version' => '', + /* + * If you'd like to specify an API version manually it can be done here. + * Format looks like '32.0' + */ + 'version' => '', - /** - * An optional redirect URL can be specified after the authentication is complete. - * If you override the routes included in this package, the authentication will return void. - */ - 'authRedirect' => '/', + /* + * An optional redirect URL can be specified after the authentication is complete. + * If you override the routes included in this package, the authentication will return void. + */ + 'authRedirect' => '/', - /** - * Optional (and not recommended) if you need to override the instance_url returned from Saleforce - */ - 'instanceURL' => '', + /* + * Optional (and not recommended) if you need to override the instance_url returned from Saleforce + */ + 'instanceURL' => '', - /** - * Language - */ - 'language' => 'en_US' + /* + * Language + */ + 'language' => 'en_US', -); \ No newline at end of file +];