From e8fe8fd1c0a4abd836b2b38aacf9c3fd831638cd Mon Sep 17 00:00:00 2001 From: Christian Stocker Date: Fri, 15 Mar 2024 14:46:23 +0100 Subject: [PATCH] lint:fix --- .../DynamicMetadataInterface.php | 2 -- src/Core/SourceImage.php | 3 +- src/Core/Stack.php | 2 +- src/Core/StackCollection.php | 2 +- src/Core/StackUri.php | 2 +- src/Core/UriComponents.php | 2 -- src/Core/UserApiKey.php | 2 +- src/Core/UserApiToken.php | 2 +- src/Factory.php | 6 ++-- src/Image.php | 16 ++++----- src/LocalImage/AbstractLocalImage.php | 12 +++---- src/LocalImage/FileInfo.php | 6 ++-- src/LocalImage/RokkaHash.php | 2 +- src/LocalImage/StringContent.php | 4 +-- src/SearchHelper.php | 1 + src/TemplateHelper.php | 33 +++++++++---------- src/UriHelper.php | 12 +++---- src/User.php | 10 +++--- 18 files changed, 57 insertions(+), 62 deletions(-) diff --git a/src/Core/DynamicMetadata/DynamicMetadataInterface.php b/src/Core/DynamicMetadata/DynamicMetadataInterface.php index dfbf6c6..7fc8fd7 100644 --- a/src/Core/DynamicMetadata/DynamicMetadataInterface.php +++ b/src/Core/DynamicMetadata/DynamicMetadataInterface.php @@ -23,8 +23,6 @@ public static function createFromDecodedJsonResponse($data); /** * Get the data, which should be json-fied later. - * - * @return mixed */ public function getForJson(); } diff --git a/src/Core/SourceImage.php b/src/Core/SourceImage.php index fc3ef64..74ba942 100644 --- a/src/Core/SourceImage.php +++ b/src/Core/SourceImage.php @@ -113,7 +113,6 @@ class SourceImage * @param string $shortHash The short hash * @param bool $protected Is image protected * @param bool $locked Is image locked - * @param mixed $mimetype */ public function __construct( $organization, @@ -165,7 +164,7 @@ public static function createFromDecodedJsonResponse(array $data): self $data['user_metadata'] = []; } else { foreach ($data['user_metadata'] as $key => $value) { - if (0 === strpos($key, 'date:')) { + if (str_starts_with($key, 'date:')) { $data['user_metadata'][$key] = new \DateTime($value); } } diff --git a/src/Core/Stack.php b/src/Core/Stack.php index 6d1c3de..3676d73 100644 --- a/src/Core/Stack.php +++ b/src/Core/Stack.php @@ -35,7 +35,7 @@ class Stack extends AbstractStack * @param array $stackOptions Collection of stack options * @param \DateTime $created Created at */ - public function __construct($organization = null, $name = null, array $stackOperations = [], array $stackOptions = [], \DateTime $created = null) + public function __construct($organization = null, $name = null, array $stackOperations = [], array $stackOptions = [], ?\DateTime $created = null) { parent::__construct($name, $stackOperations, $stackOptions); $this->organization = $organization; diff --git a/src/Core/StackCollection.php b/src/Core/StackCollection.php index a872c23..81fb09e 100644 --- a/src/Core/StackCollection.php +++ b/src/Core/StackCollection.php @@ -27,7 +27,7 @@ class StackCollection implements \Countable, \Iterator * * @param array $stacks Array of stacks */ - public function __construct(array $stacks, string $cursor = null) + public function __construct(array $stacks, ?string $cursor = null) { foreach ($stacks as $stack) { if (!($stack instanceof Stack)) { diff --git a/src/Core/StackUri.php b/src/Core/StackUri.php index 18c98d7..91c675f 100644 --- a/src/Core/StackUri.php +++ b/src/Core/StackUri.php @@ -36,7 +36,7 @@ public function __construct($name = null, array $stackOperations = [], array $st { parent::__construct($name, $stackOperations, $stackOptions, $stackVariables); - if (null !== $name && false !== strpos($name, '/')) { + if (null !== $name && str_contains($name, '/')) { // Some part of a rokka URL can have // in it, but it means nothing, remove them here. $name = preg_replace('#/{2,}#', '/', $name); if (!\is_string($name)) { diff --git a/src/Core/UriComponents.php b/src/Core/UriComponents.php index d434c45..a2aa573 100644 --- a/src/Core/UriComponents.php +++ b/src/Core/UriComponents.php @@ -51,8 +51,6 @@ public function __construct($stack, $hash = null, $format = null, $filename = nu * Creates a UriComponent object from an array with 'stack', 'hash', 'format', 'filename' and 'stack' as keys. * * @since 1.2.0 - * - * @param mixed $config */ public static function createFromArray($config): self { diff --git a/src/Core/UserApiKey.php b/src/Core/UserApiKey.php index a503e84..8ab03e0 100644 --- a/src/Core/UserApiKey.php +++ b/src/Core/UserApiKey.php @@ -52,7 +52,7 @@ public function __construct($id, $created, $accessed, $comment, $apiKey) * * @param array $apiKeys * - * @return \Rokka\Client\Core\UserApiKey + * @return UserApiKey */ public static function createFromArray($apiKeys) { diff --git a/src/Core/UserApiToken.php b/src/Core/UserApiToken.php index 787bb25..0a42643 100644 --- a/src/Core/UserApiToken.php +++ b/src/Core/UserApiToken.php @@ -31,7 +31,7 @@ public function __construct($token, $payload) * * @param array $resonse * - * @return \Rokka\Client\Core\UserApiToken + * @return UserApiToken */ public static function createFromArray($resonse) { diff --git a/src/Factory.php b/src/Factory.php index b597f0f..d755dea 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -37,7 +37,7 @@ class Factory * * @throws \RuntimeException * - * @return Image + * @return ImageClient */ public static function getImageClient($organization, $apiKey, $options = []) { @@ -152,8 +152,8 @@ private static function retryDecider() return function ( $retries, Request $request, - Response $response = null, - TransferException $exception = null + ?Response $response = null, + ?TransferException $exception = null ) { // Limit the number of retries to 10 if ($retries >= 10) { diff --git a/src/Image.php b/src/Image.php index a0539d2..3f0bbf1 100644 --- a/src/Image.php +++ b/src/Image.php @@ -39,7 +39,7 @@ class Image extends Base /** * @var string|null the render base url like foo-org.rokka.io */ - private $renderBaseUrl = null; + private $renderBaseUrl; /** * Constructor. @@ -470,13 +470,13 @@ public function createStack( * * Example: * ```language-php - $stack = new Stack(null, 'teststack'); - $stack->addStackOperation(new StackOperation('resize', ['width' => 200, 'height' => 200])); - $stack->addStackOperation(new StackOperation('rotate', ['angle' => 45])); - $stack->setStackOptions(['jpg.quality' => 80]); - $requestConfig = ['overwrite' => true]; - $stack = $client->saveStack($stack, $requestConfig); - echo 'Created stack ' . $stack->getName() . PHP_EOL; + * $stack = new Stack(null, 'teststack'); + * $stack->addStackOperation(new StackOperation('resize', ['width' => 200, 'height' => 200])); + * $stack->addStackOperation(new StackOperation('rotate', ['angle' => 45])); + * $stack->setStackOptions(['jpg.quality' => 80]); + * $requestConfig = ['overwrite' => true]; + * $stack = $client->saveStack($stack, $requestConfig); + * echo 'Created stack ' . $stack->getName() . PHP_EOL; * ``` * The only requestConfig option currently can be * ['overwrite' => true|false] (false is the default) diff --git a/src/LocalImage/AbstractLocalImage.php b/src/LocalImage/AbstractLocalImage.php index 7dde5ae..cc4d80b 100644 --- a/src/LocalImage/AbstractLocalImage.php +++ b/src/LocalImage/AbstractLocalImage.php @@ -9,9 +9,9 @@ * * See some implementation of the abstract class for examples. * - * @see \Rokka\Client\LocalImage\FileInfo - * @see \Rokka\Client\LocalImage\RokkaHash - * @see \Rokka\Client\LocalImage\StringContent + * @see FileInfo + * @see RokkaHash + * @see StringContent * @since 1.3.0 */ abstract class AbstractLocalImage @@ -21,14 +21,14 @@ abstract class AbstractLocalImage * * @var mixed|null */ - protected $context = null; + protected $context; /** * The rokka hash from the rokka API. * * @var string|null */ - protected $rokkaHash = null; + protected $rokkaHash; /** * A unique identifier for this image, can be any string. @@ -37,7 +37,7 @@ abstract class AbstractLocalImage * * @var string|null */ - protected $identifier = null; + protected $identifier; /** * @since 1.3.0 diff --git a/src/LocalImage/FileInfo.php b/src/LocalImage/FileInfo.php index e5f028c..6516f86 100644 --- a/src/LocalImage/FileInfo.php +++ b/src/LocalImage/FileInfo.php @@ -21,7 +21,7 @@ * $image = new StringContent($content, $identifier, $context); * ``` * - * @see \Rokka\Client\LocalImage\StringContent + * @see StringContent * @since 1.3.0 */ class FileInfo extends AbstractLocalImage @@ -34,12 +34,12 @@ class FileInfo extends AbstractLocalImage /** * @var string|null */ - private $content = null; + private $content; /** * @var string|null */ - private $filename = null; + private $filename; public function __construct(\SplFileInfo $image, $identifier = null, $context = null) { diff --git a/src/LocalImage/RokkaHash.php b/src/LocalImage/RokkaHash.php index c54cbe8..97f1844 100644 --- a/src/LocalImage/RokkaHash.php +++ b/src/LocalImage/RokkaHash.php @@ -24,7 +24,7 @@ class RokkaHash extends AbstractLocalImage /** * @var string|null */ - private $content = null; + private $content; /** * @var TemplateHelper|null diff --git a/src/LocalImage/StringContent.php b/src/LocalImage/StringContent.php index 8830285..d08e9b9 100644 --- a/src/LocalImage/StringContent.php +++ b/src/LocalImage/StringContent.php @@ -13,7 +13,7 @@ * $image = new StringContent($content, $identifier, $context); * ``` * - * @see \Rokka\Client\LocalImage\FileInfo + * @see FileInfo * @since 1.3.0 */ class StringContent extends AbstractLocalImage @@ -21,7 +21,7 @@ class StringContent extends AbstractLocalImage /** * @var string|null */ - private $content = null; + private $content; /** * @param string|null $image diff --git a/src/SearchHelper.php b/src/SearchHelper.php index a83ed30..5658a5f 100644 --- a/src/SearchHelper.php +++ b/src/SearchHelper.php @@ -20,6 +20,7 @@ public static function validateFieldName($fieldName) if ('deletedDate' === $fieldName) { return true; } + // Field names must be shorter than 54 chars, and match the given format. return 54 > \strlen($fieldName) && (1 === preg_match('/^(user:((str|array|date|latlon|int|double):)?)?[a-z0-9_]{1,54}$/', $fieldName) || 1 === preg_match('/^((dynamic|static):((str|array|date|latlon|int|double):))?[a-z0-9_]+:[a-z0-9_]{1,54}$/', $fieldName)); diff --git a/src/TemplateHelper.php b/src/TemplateHelper.php index 56d449b..98d7726 100644 --- a/src/TemplateHelper.php +++ b/src/TemplateHelper.php @@ -45,7 +45,7 @@ class TemplateHelper private $rokkaClientOptions; /** - * @var \Rokka\Client\Image + * @var Image */ private $imageClient; @@ -61,7 +61,7 @@ class TemplateHelper public function __construct( $organization, $apiKey, - AbstractCallbacks $callbacks = null, + ?AbstractCallbacks $callbacks = null, $publicRokkaDomain = null, $options = [] ) { @@ -136,11 +136,11 @@ public function getHashMaybeUpload(AbstractLocalImage $image) * @return string */ public function getStackUrl( - $image, - $stack, - $format = 'jpg', - $seo = null, - $seoLanguage = 'de' + $image, + $stack, + $format = 'jpg', + $seo = null, + $seoLanguage = 'de' ) { if (null == $image) { return ''; @@ -327,7 +327,7 @@ public static function getBackgroundImageStyle($url, array $sizes = ['2x']) * * @return string */ - public function getImagename(AbstractLocalImage $image = null) + public function getImagename(?AbstractLocalImage $image = null) { if (null === $image) { return ''; @@ -357,11 +357,11 @@ public function getImagename(AbstractLocalImage $image = null) * @return string */ public function generateRokkaUrl( - $hash, - $stack, - $format = 'jpg', - $seo = null, - $seoLanguage = 'de' + $hash, + $stack, + $format = 'jpg', + $seo = null, + $seoLanguage = 'de' ) { if (null === $format) { $format = 'jpg'; @@ -385,7 +385,7 @@ public function generateRokkaUrl( * * @throws \RuntimeException * - * @return \Rokka\Client\Image + * @return Image */ public function getRokkaClient() { @@ -439,7 +439,6 @@ public static function slugify($text, $language = 'de') * * @param AbstractLocalImage|string|\SplFileInfo $input * @param string|null $identifier - * @param mixed $context * * @throws \RuntimeException * @@ -470,7 +469,7 @@ public function getImageObject($input, $identifier = null, $context = null) // we can't trust callers to only provide $input in one of the supported types // @phpstan-ignore-next-line - $inputType = \is_object($input) ? \get_class($input) : \gettype($input); + $inputType = \is_object($input) ? $input::class : \gettype($input); throw new \RuntimeException('Can not create a source image from input of type '.$inputType); } @@ -525,7 +524,7 @@ private function generateRokkaUrlWithImage( $hash, $stack, $format = 'jpg', - AbstractLocalImage $image = null, + ?AbstractLocalImage $image = null, $seoLanguage = 'de' ) { return $this->generateRokkaUrl($hash, $stack, $format, $this->getImagename($image), $seoLanguage); diff --git a/src/UriHelper.php b/src/UriHelper.php index 42028f2..64baa9d 100644 --- a/src/UriHelper.php +++ b/src/UriHelper.php @@ -112,7 +112,7 @@ public static function addOptionsToUri(UriInterface $uri, $options, $shortNames * * @return UriInterface */ - public static function composeUri($components, UriInterface $uri = null, $shortNames = true) + public static function composeUri($components, ?UriInterface $uri = null, $shortNames = true) { if (\is_array($components)) { $components = UriComponents::createFromArray($components); @@ -160,13 +160,13 @@ public static function decomposeUri(UriInterface $uri) $pathPattern = '(?-.+-)'; $path = $uri->getPath(); // hash with seo-filename - if (preg_match('#^/'.$stackPattern.'/'.$hashPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) || + if (preg_match('#^/'.$stackPattern.'/'.$hashPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) // hash without seo-filename - preg_match('#^/'.$stackPattern.'/'.$hashPattern.'.'.$formatPattern.'$#', $path, $matches) || + || preg_match('#^/'.$stackPattern.'/'.$hashPattern.'.'.$formatPattern.'$#', $path, $matches) // remote_path with seo-filename - preg_match('#^/'.$stackPattern.'/'.$pathPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) || + || preg_match('#^/'.$stackPattern.'/'.$pathPattern.'/'.$filenamePattern.'\.'.$formatPattern.'$#', $path, $matches) // remote_path without seo-filename - preg_match('#^/'.$stackPattern.'/'.$pathPattern.'.'.$formatPattern.'$#', $path, $matches)) { + || preg_match('#^/'.$stackPattern.'/'.$pathPattern.'.'.$formatPattern.'$#', $path, $matches)) { $uriComponents = UriComponents::createFromArray($matches); $inQuery = Query::parse($uri->getQuery()); @@ -269,7 +269,7 @@ public static function signUrl($url, $signKey, $until = null, $roundDateUpTo = 3 * * @return array */ - private static function getUriStringFromStackConfig(array $config, $shortNames = true, UriInterface $uri = null) + private static function getUriStringFromStackConfig(array $config, $shortNames = true, ?UriInterface $uri = null) { $newOptions = []; diff --git a/src/User.php b/src/User.php index df8fe09..564f84c 100644 --- a/src/User.php +++ b/src/User.php @@ -98,9 +98,9 @@ public function getCurrentUserId() * * @param string|null $comment Optional comment * - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException */ - public function addUserApiKey(string $comment = null): UserApiKey + public function addUserApiKey(?string $comment = null): UserApiKey { $contents = $this ->call('POST', self::USER_API_KEYS_RESOURCE, ['json' => [ @@ -120,7 +120,7 @@ public function addUserApiKey(string $comment = null): UserApiKey * * @since 1.16.0 * - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException */ public function getCurrentUserApiKey(): UserApiKey { @@ -138,7 +138,7 @@ public function getCurrentUserApiKey(): UserApiKey * * @since 1.16.0 * - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return bool returns false, if key didn't exist, true if operation succeeded */ @@ -188,7 +188,7 @@ public function getCurrentUser() * @param string|null $apiKey The api key, if different from the base one * @param array $parameters The /user/apikeys/token query parameters * - * @throws \GuzzleHttp\Exception\GuzzleException + * @throws GuzzleException * * @return UserApiToken */