Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #309

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.php_cs.cache
.php-cs-fixer.cache
phpunit.xml
composer.lock
coverage
Expand Down
2 changes: 1 addition & 1 deletion .php_cs → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
->in(__DIR__.'/src')
->in(__DIR__.'/tests');

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setFinder($finder)
->setRules([
'@Symfony' => true,
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"require-dev": {
"phpunit/phpunit": "^8.4",
"phpstan/phpstan": "^0.10.1",
"friendsofphp/php-cs-fixer": "^2.3",
"phpstan/phpstan": "^1.10",
"friendsofphp/php-cs-fixer": "^3.4",
"mockery/mockery": "^1.1",
"ramsey/uuid": "^4.1"
},
Expand Down
8 changes: 4 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
ignoreErrors:
# Ignore type errors for passing a Mock
- '#.*MockObject given.*#'
- '#.*MockInterface given.*#'
level: 4
paths:
- src
- tests
16 changes: 8 additions & 8 deletions src/Conversations/ConversationLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

class ConversationLinks
{
const MAILBOX = 'mailbox';
const PRIMARY_CUSTOMER = 'primaryCustomer';
const CREATED_BY_CUSTOMER = 'createdByCustomer';
const CREATED_BY_USER = 'createdByUser';
const CLOSED_BY = 'closedBy';
const THREADS = 'threads';
const ASSIGNEE = 'assignee';
const WEB = 'web';
public const MAILBOX = 'mailbox';
public const PRIMARY_CUSTOMER = 'primaryCustomer';
public const CREATED_BY_CUSTOMER = 'createdByCustomer';
public const CREATED_BY_USER = 'createdByUser';
public const CLOSED_BY = 'closedBy';
public const THREADS = 'threads';
public const ASSIGNEE = 'assignee';
public const WEB = 'web';
}
3 changes: 2 additions & 1 deletion src/Conversations/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function setValue($value): self
return $this;
}

public function getText(): ?string {
public function getText(): ?string
{
return $this->text;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Conversations/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class Status
/**
* We're using the verbiage "ANY" instead of "ALL" because a conversation can only have a single status, not multiple.
*/
const ANY = 'all';
const ACTIVE = 'active';
const CLOSED = 'closed';
const OPEN = 'open';
const PENDING = 'pending';
const SPAM = 'spam';
public const ANY = 'all';
public const ACTIVE = 'active';
public const CLOSED = 'closed';
public const OPEN = 'open';
public const PENDING = 'pending';
public const SPAM = 'spam';
}
12 changes: 6 additions & 6 deletions src/Customers/CustomerLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class CustomerLinks
{
const ADDRESS = 'address';
const CHATS = 'chats';
const EMAILS = 'emails';
const PHONES = 'phones';
const SOCIAL_PROFILES = 'social-profiles';
const WEBSITES = 'websites';
public const ADDRESS = 'address';
public const CHATS = 'chats';
public const EMAILS = 'emails';
public const PHONES = 'phones';
public const SOCIAL_PROFILES = 'social-profiles';
public const WEBSITES = 'websites';
}
2 changes: 1 addition & 1 deletion src/Customers/Entry/CustomerEntryEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CustomerEntryEndpoint extends Endpoint
public const CUSTOMER_SOCIAL = '/v2/customers/%d/social-profiles/%d';
public const CREATE_CUSTOMER_WEBSITE = '/v2/customers/%d/websites';
public const CUSTOMER_WEBSITE = '/v2/customers/%d/websites/%d';
public const CUSTOMER_PROPERTIES= '/v2/customers/%d/properties';
public const CUSTOMER_PROPERTIES = '/v2/customers/%d/properties';

public function createAddress(int $customerId, Address $address): ?int
{
Expand Down
8 changes: 4 additions & 4 deletions src/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ protected function loadPage(
): PagedCollection {
/** @var HalPagedResources $pagedResources */
$pagedResources = $this->restClient->getResources(
$entityClass,
$rel,
$uri
);
$entityClass,
$rel,
$uri
);

$mapClosure = function (HalResource $resource) {
return $resource->getEntity();
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/PagedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class PagedCollection extends Collection
/**
* The link name for the templated page URI.
*/
const REL_PAGE = 'page';
public const REL_PAGE = 'page';

/**
* The variable name for the page number in the templated URI.
*/
const PAGE_VARIABLE = 'page';
public const PAGE_VARIABLE = 'page';

/**
* @var HalPageMetadata
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Hal/HalDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

class HalDeserializer
{
const LINKS = '_links';
const EMBEDDED = '_embedded';
public const LINKS = '_links';
public const EMBEDDED = '_embedded';

public static function deserializeDocument(string $json): HalDocument
{
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Hal/HalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ class HalLink
/**
* The first page.
*/
const REL_FIRST = 'first';
public const REL_FIRST = 'first';

/**
* The last page.
*/
const REL_LAST = 'last';
public const REL_LAST = 'last';

/**
* The next page.
*/
const REL_NEXT = 'next';
public const REL_NEXT = 'next';

/**
* The previous page.
*/
const REL_PREVIOUS = 'previous';
public const REL_PREVIOUS = 'previous';

/**
* The self relation.
*/
const REL_SELF = 'self';
public const REL_SELF = 'self';

/**
* @var string
Expand Down Expand Up @@ -77,6 +77,6 @@ public function expand(array $params): string
throw new RuntimeException(sprintf('The link "%s" is not templated', $this->getRel()));
}

return (new UriTemplate)->expand($this->getHref(), $params);
return (new UriTemplate())->expand($this->getHref(), $params);
}
}
3 changes: 2 additions & 1 deletion src/Http/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use HelpScout\Api\Http\Hal\HalResource;
use HelpScout\Api\Http\Hal\HalResources;
use HelpScout\Api\Reports\Report;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class RestClient
Expand Down Expand Up @@ -167,7 +168,7 @@ private function encodeEntity(Extractable $entity): string
/**
* @return mixed|ResponseInterface
*/
private function send(Request $request)
private function send(RequestInterface $request)
{
$options = [
'base_uri' => self::BASE_URI,
Expand Down
3 changes: 3 additions & 0 deletions src/Http/RestClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function build($tokenRefreshedCallback = null): RestClient
);
}

/**
* @internal
*/
protected function getGuzzleClient(): Client
{
$options = $this->getOptions();
Expand Down
4 changes: 2 additions & 2 deletions src/Mailboxes/MailboxLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

class MailboxLinks
{
const FIELDS = 'fields';
const FOLDERS = 'folders';
public const FIELDS = 'fields';
public const FOLDERS = 'folders';
}
7 changes: 2 additions & 5 deletions tests/Authentication/AuthenticationIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ public function testAuthenticatorFetchesTokensWithClientCredentials()
'Authorization' => 'Bearer fdsafdas',
];

$authenticator = new Authenticator(new Client(), $auth);
$authenticator = new Authenticator($this->guzzle, $auth);

$authenticator->setClient($this->guzzle);
$result = $authenticator->getAuthHeader();
$this->assertSame($expectedResult, $result);
}
Expand Down Expand Up @@ -162,10 +161,8 @@ public function testAuthenticatorFetchesTokensWithRefreshCredentials()
'Authorization' => 'Bearer fdsafdas',
];

$authenticator = new Authenticator(new Client(), $auth);
$authenticator = new Authenticator($this->guzzle, $auth);

/* @var Client $client */
$authenticator->setClient($this->guzzle);
$result = $authenticator->getAuthHeader();
$this->assertSame($expectedResult, $result);

Expand Down
2 changes: 1 addition & 1 deletion tests/Conversations/Threads/Support/HasCustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use HelpScout\Api\Customers\Customer;
use HelpScout\Api\Support\HasCustomer;
use PHPStan\Testing\TestCase;
use PHPUnit\Framework\TestCase;

class HasCustomerTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace HelpScout\Api\Tests\Conversations\Threads\Support;

use HelpScout\Api\Conversations\Threads\Support\HasPartiesToBeNotified;
use PHPStan\Testing\TestCase;
use PHPUnit\Framework\TestCase;

class HasPartiesToBeNotifiedTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Conversations/Threads/Support/HasUserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use HelpScout\Api\Conversations\Threads\Support\HasUser;
use HelpScout\Api\Users\User;
use PHPStan\Testing\TestCase;
use PHPUnit\Framework\TestCase;

class HasUserTest extends TestCase
{
Expand Down
5 changes: 0 additions & 5 deletions tests/Http/Hal/Entity/StubPayloads.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ public static function getPagedResources(): string
],
];

if (empty($entities)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is dead code: $entities cannot be empty

// The _embedded key is not set when empty
unset($data['_embedded']);
}

return json_encode($data);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Http/RestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function testSendingRequestRefreshesToken()
->with(\Mockery::on(function (Request $request) {
// Ensure retry request includes new auth headers.
$this->assertSame(['the-value'], $request->getHeader('the-header'));

return true;
}), \Mockery::any())
->andReturn($response);
Expand Down