Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
slince committed Oct 22, 2023
1 parent fd5c218 commit ac5e8c6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"require": {
"php": "^7.2||^8.0",
"php": "8.0",
"doctrine/inflector": "^1.2|^2.0",
"doctrine/cache": "^1.0",
"guzzlehttp/guzzle": "^7.0",
Expand Down
6 changes: 3 additions & 3 deletions src/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

use Slince\Shopify\Exception\InvalidArgumentException;

class AccessToken
final class AccessToken
{
/**
* @var string
*/
protected $token;
protected string $token;

public function __construct(string $token)
{
Expand All @@ -35,7 +35,7 @@ public function __construct(string $token)
*
* @return string
*/
public function __toString()
public function __toString(): string
{
return $this->token;
}
Expand Down
72 changes: 36 additions & 36 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,41 +86,41 @@ class Client
/**
* @var Container
*/
protected $container;
protected Container $container;

/**
* @var CredentialInterface
*/
protected $credential;
protected CredentialInterface $credential;

/**
* The shop.
*
* @var string
*/
protected $shop;
protected string $shop;

/**
* @var string
*/
protected $apiVersion = '2022-04';
protected string $apiVersion = '2023-10';

/**
* @var ResponseInterface
*/
protected $lastResponse;
protected ResponseInterface $lastResponse;

/**
* @var MiddlewareChain
*/
protected $middlewares;
protected MiddlewareChain $middlewares;

/**
* Array of services classes.
*
* @var array
*/
public $serviceClass =[
public array $serviceClass =[
// Access
Service\Access\AccessScopeManager::class,
Service\Access\StorefrontAccessTokenManager::class,
Expand Down Expand Up @@ -188,24 +188,24 @@ class Client
/**
* @var array
*/
protected $metaDirs = [
protected array $metaDirs = [
'Slince\\Shopify\\Model' => __DIR__.'/../config/serializer'
];

/**
* @var string
*/
protected $metaCacheDir;
protected string $metaCacheDir;

/**
* @var Hydrator
* @var Hydrator|null
*/
protected $hydrator;
protected ?Hydrator $hydrator = null;

/**
* @var HttpClient
*/
protected $httpClient;
protected HttpClient $httpClient;

public function __construct($shop, CredentialInterface $credential, array $options = [])
{
Expand All @@ -232,7 +232,7 @@ public function __call($name, $arguments)
*
* @return CredentialInterface
*/
public function getCredential()
public function getCredential(): CredentialInterface
{
return $this->credential;
}
Expand All @@ -242,7 +242,7 @@ public function getCredential()
*
* @param string $shop
*/
public function setShop($shop)
public function setShop(string $shop): void
{
if (!preg_match('/^[a-zA-Z0-9\-]{3,100}\.myshopify\.(?:com|io)$/', $shop)) {
throw new InvalidArgumentException(
Expand All @@ -257,7 +257,7 @@ public function setShop($shop)
*
* @return string
*/
public function getShop()
public function getShop(): string
{
return $this->shop;
}
Expand All @@ -266,11 +266,11 @@ public function getShop()
* Perform a GET request.
*
* @param string $resource
* @param array $query
* @param array $query
*
* @return array
*/
public function get($resource, $query = [])
public function get(string $resource, array $query = []): array
{
return $this->createRequest('GET', $this->buildUrl($resource), [
'query' => $query,
Expand All @@ -281,12 +281,12 @@ public function get($resource, $query = [])
* Perform a POST request.
*
* @param string $resource
* @param array $data
* @param array $query
* @param array $data
* @param array $query
*
* @return array
*/
public function post($resource, $data, $query = [])
public function post(string $resource, array $data, array $query = []): array
{
return $this->createRequest('POST', $this->buildUrl($resource), [
'query' => $query,
Expand All @@ -298,12 +298,12 @@ public function post($resource, $data, $query = [])
* Perform a PUT request.
*
* @param string $resource
* @param array $data
* @param array $query
* @param array $data
* @param array $query
*
* @return array
*/
public function put($resource, $data, $query = [])
public function put(string $resource, array $data, array $query = []): array
{
return $this->createRequest('PUT', $this->buildUrl($resource), [
'query' => $query,
Expand All @@ -315,9 +315,9 @@ public function put($resource, $data, $query = [])
* Perform a DELETE request.
*
* @param string $resource
* @param array $query
* @param array $query
*/
public function delete($resource, $query = [])
public function delete(string $resource, array $query = []): void
{
$this->createRequest('DELETE', $this->buildUrl($resource), [
'query' => $query
Expand All @@ -332,7 +332,7 @@ public function delete($resource, $query = [])
* @param array $options
* @return array
*/
public function createRequest($method, $uri, $options = [])
public function createRequest(string $method, string $uri, array $options = []): array
{
$request = new Request($method, $uri, [
'Content-Type' => 'application/json',
Expand All @@ -354,7 +354,7 @@ public function createRequest($method, $uri, $options = [])
* @return ResponseInterface
* @codeCoverageIgnore
*/
protected function sendRequest(RequestInterface $request, array $options = [])
protected function sendRequest(RequestInterface $request, array $options = []): ResponseInterface
{
$request = $this->credential->applyToRequest($request);
$request = $request->withHeader('User-Agent', static::NAME . '/' . static::VERSION);
Expand All @@ -374,7 +374,7 @@ protected function sendRequest(RequestInterface $request, array $options = [])
return $response;
}

protected function raiseException(RequestInterface $request, ResponseInterface $response)
protected function raiseException(RequestInterface $request, ResponseInterface $response): void
{
if ($response->getStatusCode() < 300) {
return;
Expand Down Expand Up @@ -404,7 +404,7 @@ protected function raiseException(RequestInterface $request, ResponseInterface $
*
* @return ResponseInterface
*/
public function getLastResponse()
public function getLastResponse(): ResponseInterface
{
return $this->lastResponse;
}
Expand All @@ -413,10 +413,10 @@ public function getLastResponse()
* Builds an url by given resource name.
*
* @param string $resource
* @param string $versioning
* @param bool $versioning
* @return string
*/
public function buildUrl($resource, $versioning = true)
public function buildUrl(string $resource, bool $versioning = true): string
{
return $versioning ? sprintf('https://%s/admin/api/%s/%s.json', $this->shop, $this->apiVersion, $resource)
: sprintf('https://%s/admin/%s.json', $this->shop, $resource);
Expand Down Expand Up @@ -468,7 +468,7 @@ public function getMiddlewares(): MiddlewareChain
*
* @return Hydrator
*/
public function getHydrator()
public function getHydrator(): Hydrator
{
if ($this->hydrator) {
return $this->hydrator;
Expand All @@ -483,10 +483,10 @@ public function getHydrator()
* @param string $path
* @throws RuntimeException
*/
public function addMetaDir($namespace, $path)
public function addMetaDir(string $namespace, string $path): void
{
if ($this->hydrator) {
throw new RuntimeException(sprintf('The hydrator has been built, you should add meta dir before getting manager.'));
throw new RuntimeException('The hydrator has been built, you should add meta dir before getting manager.');
}
$this->metaDirs[$namespace] = $path;
}
Expand All @@ -497,7 +497,7 @@ public function addMetaDir($namespace, $path)
* @param string $serviceClass
* @throws InvalidArgumentException
*/
public function addServiceClass($serviceClass)
public function addServiceClass(string $serviceClass): void
{
if (!is_subclass_of($serviceClass, ManagerInterface::class)) {
throw new InvalidArgumentException(sprintf('The service class "%s" should implement "ManagerInterface"', $serviceClass));
Expand All @@ -509,7 +509,7 @@ public function addServiceClass($serviceClass)
/**
* Initialize base services.
*/
protected function initializeBaseServices()
protected function initializeBaseServices(): void
{
foreach ($this->serviceClass as $serviceClass) {
$this->container->register($serviceClass::getServiceName(), $serviceClass);
Expand Down
14 changes: 7 additions & 7 deletions src/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ final class Inflector
*/
protected static $inflector;

protected static function getInflector()
protected static function getInflector(): \Doctrine\Inflector\Inflector
{
if (null !== static::$inflector) {
return static::$inflector;
if (null !== Inflector::$inflector) {
return Inflector::$inflector;
}
return static::$inflector = InflectorFactory::create()->build();
return Inflector::$inflector = InflectorFactory::create()->build();
}

public static function pluralize(string $word)
public static function pluralize(string $word): string
{
return static::getInflector()->pluralize($word);
}

public static function tableize(string $word)
public static function tableize(string $word): string
{
return static::getInflector()->tableize($word);
}

public static function classify(string $word)
public static function classify(string $word): string
{
return static::getInflector()->classify($word);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/CallableMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class CallableMiddleware implements MiddlewareInterface
{
/**
* @var Client
* @var callable
*/
protected $callable;

Expand Down
8 changes: 4 additions & 4 deletions src/PrivateAppCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ class PrivateAppCredential implements CredentialInterface
/**
* @var string
*/
protected $apiKey;
protected string $apiKey;

/**
* @var string
*/
protected $password;
protected string $password;

/**
* @var string
*/
protected $sharedSecret;
protected string $sharedSecret;

public function __construct($apiKey, $password, $sharedSecret)
{
Expand All @@ -42,7 +42,7 @@ public function __construct($apiKey, $password, $sharedSecret)
/**
* @return string
*/
public function getApiKey()
public function getApiKey(): string
{
return $this->apiKey;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PublicAppCredential.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class PublicAppCredential implements CredentialInterface
/**
* @var AccessToken
*/
protected $accessToken;
protected AccessToken $accessToken;

public function __construct($accessToken)
public function __construct(AccessToken|string $accessToken)
{
$this->accessToken = $accessToken instanceof AccessToken ? $accessToken : new AccessToken($accessToken);
}
Expand Down

0 comments on commit ac5e8c6

Please sign in to comment.