From 248d3c6444fbfba24b3887ce9c083c5f28198593 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 15 Mar 2024 17:19:48 +0100 Subject: [PATCH] apply cs fixes --- .php-cs-fixer.dist.php | 3 ++ composer.json | 4 +-- phpstan.neon | 8 +++-- scripts/doctum-config.php | 2 +- src/Core/DynamicMetadata/DetectionFace.php | 3 ++ .../DynamicMetadataInterface.php | 2 +- src/Core/DynamicMetadata/SubjectArea.php | 3 ++ src/Core/DynamicMetadata/Version.php | 7 ++-- src/Core/SourceImage.php | 34 ++++++++---------- src/Core/Stack.php | 2 +- src/Core/StackCollection.php | 2 +- src/Core/StackUri.php | 2 +- src/Core/UriComponents.php | 4 +-- src/Core/UserApiKey.php | 2 +- src/Core/UserApiToken.php | 2 +- src/Factory.php | 6 ++-- src/Image.php | 36 +++++++++---------- 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 | 35 +++++++++--------- src/UriHelper.php | 20 ++++++----- src/User.php | 12 +++---- tests/Core/SourceImageTest.php | 15 +++----- tests/Core/StackTest.php | 6 ---- tests/Core/StackUriTest.php | 4 +-- tests/Core/UriComponentTest.php | 1 - tests/DynamicMetadataHelperTest.php | 3 -- tests/ImageTest.php | 9 ++--- tests/SignUrlsTest.php | 8 ++--- tests/TemplateHelperTest.php | 6 +--- tests/UriHelperTest.php | 32 ++++++----------- 34 files changed, 137 insertions(+), 161 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index dff6d5a..cf2274c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,5 +1,7 @@ notPath('src/AppBundle/Command/TestCommand.php') ->exclude('tests/*/Fixtures') @@ -10,6 +12,7 @@ $config = new PhpCsFixer\Config(); return $config + ->setParallelConfig(ParallelConfigFactory::detect()) ->setRiskyAllowed(true) ->setRules([ '@Symfony' => true, diff --git a/composer.json b/composer.json index 596700c..134055e 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,8 @@ "require-dev": { "phpunit/phpunit": "^9.5.25", "symfony/var-dumper": "^3.4|^4.0|^5.0|^6.0", - "phpstan/phpstan": "^1.7", - "friendsofphp/php-cs-fixer": "^3.4" + "phpstan/phpstan": "^1.11", + "friendsofphp/php-cs-fixer": "^3.57" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index ca4d9fd..d12d8a1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,5 +2,9 @@ parameters: level: 7 paths: - src/ - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false + treatPhpDocTypesAsCertain: false + ignoreErrors: + - + identifier: missingType.generics + - + identifier: missingType.iterableValue diff --git a/scripts/doctum-config.php b/scripts/doctum-config.php index 423147b..3cb1efd 100644 --- a/scripts/doctum-config.php +++ b/scripts/doctum-config.php @@ -1,7 +1,7 @@ $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..8280bd0 100644 --- a/src/Core/UriComponents.php +++ b/src/Core/UriComponents.php @@ -50,9 +50,9 @@ 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 array{stack: string, hash?: ?string, format?: ?string, filename?: ?string} $config * - * @param mixed $config + * @since 1.2.0 */ 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 c13f16f..1d3ad6f 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) @@ -691,12 +691,12 @@ public function setProtected($protected, $hash, $organization = '', $options = [ $callOptions['json'] = $protected; $path = implode('/', [ - self::SOURCEIMAGE_RESOURCE, - $this->getOrganizationName($organization), - $hash, - 'options', - 'protected', - ]); + self::SOURCEIMAGE_RESOURCE, + $this->getOrganizationName($organization), + $hash, + 'options', + 'protected', + ]); // delete the previous, if we're not on the first one anymore, or if we want to delete it. if (isset($options['deletePrevious']) && $options['deletePrevious']) { @@ -766,10 +766,10 @@ public function addAutolabels($hash, $organization = null): SourceImage } /** - * @param string[] $languages - * @param string $hash - * @param string|null $organization - * @param array $options, for example ['force' => true] to recreate + * @param string[] $languages + * @param string $hash + * @param string|null $organization + * @param array{force?: bool} $options if force is true, the description is generated again even if it already exists */ public function addAutodescription($languages, $hash, $organization = null, array $options = []): SourceImage { 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..ff4b147 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,7 @@ public static function slugify($text, $language = 'de') * * @param AbstractLocalImage|string|\SplFileInfo $input * @param string|null $identifier - * @param mixed $context + * @param mixed|null $context * * @throws \RuntimeException * @@ -469,8 +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..f545652 100644 --- a/src/UriHelper.php +++ b/src/UriHelper.php @@ -104,15 +104,15 @@ public static function addOptionsToUri(UriInterface $uri, $options, $shortNames * * @since 1.2.0 * - * @param array|UriComponents $components - * @param UriInterface $uri If this is provided, it will change the path for that object and return - * @param bool $shortNames if short names (like o for option or v for variables) should be used + * @param array{stack: string, hash?: ?string, format?: ?string, filename?: ?string}|UriComponents $components + * @param UriInterface $uri If this is provided, it will change the path for that object and return + * @param bool $shortNames if short names (like o for option or v for variables) should be used * * @throws \RuntimeException * * @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,15 @@ 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) + ) { + // @phpstan-ignore-next-line argument.type $uriComponents = UriComponents::createFromArray($matches); $inQuery = Query::parse($uri->getQuery()); @@ -269,7 +271,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..6299bc4 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 */ @@ -348,7 +348,7 @@ public function createUserAndMembership($roles = [Membership::ROLE_READ], $organ implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships']), ['json' => [ 'roles' => $roles, - ]]) + ]]) ->getBody() ->getContents(); diff --git a/tests/Core/SourceImageTest.php b/tests/Core/SourceImageTest.php index 14a0cb0..383dba2 100644 --- a/tests/Core/SourceImageTest.php +++ b/tests/Core/SourceImageTest.php @@ -4,7 +4,7 @@ use Rokka\Client\Core\SourceImage; use Rokka\Client\Core\SourceImageCollection; -class SourceImageTest extends \PHPUnit\Framework\TestCase +class SourceImageTest extends PHPUnit\Framework\TestCase { /** * @return array @@ -44,12 +44,12 @@ public function createFromJsonDataProvider() $testData = []; - $image = new SourceImage('organization', 'binaryHash', 'verylonghash', 'name', 'format', 'mimetype','size', 'width', 'height', [], [], [], new DateTime(), 'link', 'shorthash'); + $image = new SourceImage('organization', 'binaryHash', 'verylonghash', 'name', 'format', 'mimetype', 'size', 'width', 'height', [], [], [], new DateTime(), 'link', 'shorthash'); $testData['base-image'] = [ $image, $imageReverser($image), true, ]; - $image = new SourceImage('organization', 'binaryHash', 'verylonghash', 'name', 'format', 'mimetype','size', 'width', 'height', [], [], [], new DateTime(), 'link', 'shorthash'); + $image = new SourceImage('organization', 'binaryHash', 'verylonghash', 'name', 'format', 'mimetype', 'size', 'width', 'height', [], [], [], new DateTime(), 'link', 'shorthash'); $testData['base-image-json'] = [ $image, json_encode($imageReverser($image)), ]; @@ -61,7 +61,7 @@ public function createFromJsonDataProvider() ]; $subjectAres = new SubjectArea(10, 10, 100, 100); - $image = new SourceImage('organization', 'binaryHash', 'verylonghash', 'name', 'format', 'mimetype','size', 'width', 'height', [], ['subject_area' => $subjectAres], [], new DateTime(), 'link', 'shorthash'); + $image = new SourceImage('organization', 'binaryHash', 'verylonghash', 'name', 'format', 'mimetype', 'size', 'width', 'height', [], ['subject_area' => $subjectAres], [], new DateTime(), 'link', 'shorthash'); $testData['image-json-subject-area'] = [ $image, json_encode($imageReverser($image)), ]; @@ -72,10 +72,7 @@ public function createFromJsonDataProvider() /** * @dataProvider createFromJsonDataProvider * - * @param $expected - * @param $datat - * @param bool $isArray - * @param mixed $data + * @param bool $isArray */ public function testCreateFromJson($expected, $data, $isArray = false) { @@ -90,8 +87,6 @@ public function testCreateFromJson($expected, $data, $isArray = false) /** * @dataProvider createFromJsonDataProvider * - * @param $expected - * @param $data * @param bool $isArray */ public function testCollectionCreateFromJson($expected, $data, $isArray = false) diff --git a/tests/Core/StackTest.php b/tests/Core/StackTest.php index c645a65..039ce13 100644 --- a/tests/Core/StackTest.php +++ b/tests/Core/StackTest.php @@ -63,9 +63,6 @@ public function createFromJsonDataProvider() /** * @dataProvider createFromJsonDataProvider - * - * @param $expected - * @param $data */ public function testCreateFromJson($expected, $data) { @@ -76,13 +73,10 @@ public function testCreateFromJson($expected, $data) /** * @dataProvider createFromJsonDataProvider * - * @param $expected - * @param $data * @param bool $isArray */ public function testCollectionCreateFromJson($expected, $data, $isArray = false) { - $json = '{"items": ['.$data.'], "offset": 0}'; $stacks = StackCollection::createFromJsonResponse($json); $this->assertEquals($expected, $stacks->current()); diff --git a/tests/Core/StackUriTest.php b/tests/Core/StackUriTest.php index 7b113ec..1782b72 100644 --- a/tests/Core/StackUriTest.php +++ b/tests/Core/StackUriTest.php @@ -33,9 +33,9 @@ public function provide__construct() * @param string $name * @param array $options * @param array $operations - * @param null|string $expectedUri + * @param string|null $expectedUri */ - public function test__construct($stackName, $name, $options, $operations, $expectedUri = null) + public function testConstruct($stackName, $name, $options, $operations, $expectedUri = null) { $stack = new StackUri($stackName); $this->assertEquals($name, $stack->getName()); diff --git a/tests/Core/UriComponentTest.php b/tests/Core/UriComponentTest.php index 4c2e360..ba1ffd4 100644 --- a/tests/Core/UriComponentTest.php +++ b/tests/Core/UriComponentTest.php @@ -20,7 +20,6 @@ public function provideCreateFromArray() * @dataProvider provideCreateFromArray * * @param array $config - * @param $name */ public function testCreateFromArray($config, $name) { diff --git a/tests/DynamicMetadataHelperTest.php b/tests/DynamicMetadataHelperTest.php index 3d7e8af..098ff4c 100644 --- a/tests/DynamicMetadataHelperTest.php +++ b/tests/DynamicMetadataHelperTest.php @@ -22,9 +22,6 @@ public function provideGetDynamicMetadataClassNameData() /** * @dataProvider provideGetDynamicMetadataClassNameData - * - * @param $expected - * @param $name */ public function testGetDynamicMetadataClassName($expected, $name) { diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 7137922..cfbbc66 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -35,13 +35,8 @@ public function dataProviderGetSourceImageUri() /** * @dataProvider dataProviderGetSourceImageUri * - * @param $expected - * @param \Rokka\Client\Image $client - * @param $hash - * @param $stack - * @param $format - * @param $name - * @param string $organization + * @param string $organization + * @param mixed|null $name */ public function testGetSourceImageUri($expected, Image $client, $hash, $stack, $format, $name = null, $organization = null) { diff --git a/tests/SignUrlsTest.php b/tests/SignUrlsTest.php index ffaefd6..e10e03f 100644 --- a/tests/SignUrlsTest.php +++ b/tests/SignUrlsTest.php @@ -27,7 +27,7 @@ public function provideAddOptionsToUri() 'different sig 2 minutes later' => [ '', '?sigopts=%7B%22until%22%3A%222050-02-08T08%3A10%3A00%2B00%3A00%22%7D&sig=fa95fb5de8a284df', - (new \DateTime('2050-02-08T08:07:00+00:00')), + new \DateTime('2050-02-08T08:07:00+00:00'), ], 'keep v query' => [ '?v={"a":"b"}', @@ -62,7 +62,7 @@ public function provideAddOptionsToUri() * @throws \PHPUnit_Framework_Exception * @throws \PHPUnit_Framework_ExpectationFailedException */ - public function testCheckSignature($inputQuery = '', $expectedQuery = '', \DateTime $until = null) + public function testCheckSignature($inputQuery = '', $expectedQuery = '', ?\DateTime $until = null) { $key = 'OCOuisGe30QyocYkQN1SPErGGKunyuhZ'; $path = 'http://test.rokka.test/dynamic/c1b110.jpg'; @@ -73,9 +73,9 @@ public function testCheckSignature($inputQuery = '', $expectedQuery = '', \DateT public function testSlashSignature() { - //with leading slash + // with leading slash $this->assertEquals('/dynamic/abcdef.jpg?sig=b7789b71b470e458', (string) UriHelper::signUrl('/dynamic/abcdef.jpg', 'abcdef')); - //without leading slash, should return the same sig + // without leading slash, should return the same sig $this->assertEquals('dynamic/abcdef.jpg?sig=b7789b71b470e458', (string) UriHelper::signUrl('dynamic/abcdef.jpg', 'abcdef')); // different path leads to different sig $this->assertEquals('/dynamic/resize-width-100/abcdef.jpg?sig=6a7233a3c5bd2374', (string) UriHelper::signUrl('/dynamic/resize-width-100/abcdef.jpg', 'abcdef')); diff --git a/tests/TemplateHelperTest.php b/tests/TemplateHelperTest.php index b912934..c693539 100644 --- a/tests/TemplateHelperTest.php +++ b/tests/TemplateHelperTest.php @@ -21,7 +21,7 @@ class TemplateHelperTest extends \PHPUnit\Framework\TestCase private $testImages = ['small' => ['path' => __DIR__.'/Fixtures/Images/small-bratpfanne.jpg', 'hash' => '71775293697709c1a1ce66f05d7c011a6982a6a9']]; - public function setUp():void + protected function setUp(): void { $this->rokka = new TemplateHelper('testorg', 'key', new TestCallbacks()); parent::setUp(); @@ -56,10 +56,6 @@ public function provideStackUrl() /** * @dataProvider provideStackUrl * - * @param $image - * @param $seo - * @param $url - * * @throws \GuzzleHttp\Exception\GuzzleException */ public function testGetStackUrl($image, $seo, $url) diff --git a/tests/UriHelperTest.php b/tests/UriHelperTest.php index fad7903..2f4945b 100644 --- a/tests/UriHelperTest.php +++ b/tests/UriHelperTest.php @@ -56,11 +56,11 @@ public function provideAddOptionsToUri() ['resize-width-100--options-autoformat-true--v-w-300', 'v-w-200', 'resize-width-100--o-autoformat-true--v-w-200'], // with v in query parameter - ['', ['variables' => ['dpr' => '?d', 'a' => 'b']], 'v-a-b', true,'','?v=%7B%22dpr%22:%22?d%22%7D'], + ['', ['variables' => ['dpr' => '?d', 'a' => 'b']], 'v-a-b', true, '', '?v=%7B%22dpr%22:%22?d%22%7D'], ['v-text-lala', ['variables' => ['text' => 'Lala#', 'a' => 'b']], 'v-a-b', true, '', '?v=%7B%22text%22:%22Lala%23%22%7D'], ['v-text-lala', ['variables' => ['text' => 'Lala', 'a' => 'b']], 'v-a-b-text-Lala', true], - ['v-text-lala', ['variables' => ['text' => 'Lala?']], '', true,'','?v=%7B%22text%22:%22Lala?%22%7D'], - ['', ['variables' => ['text' => 'Lala', 'a' => 'b']], 'v-a-b-text-Lala', true, '?v=%7B%22text%22:%22Lala?%22%7D',''], + ['v-text-lala', ['variables' => ['text' => 'Lala?']], '', true, '', '?v=%7B%22text%22:%22Lala?%22%7D'], + ['', ['variables' => ['text' => 'Lala', 'a' => 'b']], 'v-a-b-text-Lala', true, '?v=%7B%22text%22:%22Lala?%22%7D', ''], ]; } @@ -112,9 +112,6 @@ public function provideDecomposeUri() /** * @dataProvider provideDecomposeUri - * - * @param $option - * @param $expectedOptions */ public function testDecomposeUri($option, $expectedOptions) { @@ -143,11 +140,10 @@ public function testDecomposeUri($option, $expectedOptions) * @param string $inputUrl * @param string|array $options * @param string $expected - * @param mixed $shortNames */ public function testAddOptionsToUri($inputUrl, $options, $expected, $shortNames = true, $requestQuery = '', $queryString = '') { - $this->assertSame('https://test.rokka.io/stackname/'.($expected ? $expected . '/' : '').'b53763.jpg'. $queryString, UriHelper::addOptionsToUriString('https://test.rokka.io/stackname/'.$inputUrl.'/b53763.jpg'.$requestQuery, $options, $shortNames)); + $this->assertSame('https://test.rokka.io/stackname/'.($expected ? $expected.'/' : '').'b53763.jpg'.$queryString, UriHelper::addOptionsToUriString('https://test.rokka.io/stackname/'.$inputUrl.'/b53763.jpg'.$requestQuery, $options, $shortNames)); } public function testGetDynamicStackFromStackObject() @@ -168,7 +164,6 @@ public function testGetDynamicStackFromStackObject() * @param string $size * @param string|null $custom * @param string $expected - * @param mixed $setWidthInUrl */ public function testGetSrcSetUrl($size, $custom, $expected, $setWidthInUrl = true) { @@ -180,30 +175,26 @@ public function testKeepQueryString() { // keep existing query strings $inputUrl = 'https://test.rokka.io/stackname/b537639e539efcc3df4459ef87c5963aa5079ca6.jpg?foo=bar&baz'; - $result = (string) \Rokka\Client\UriHelper::addOptionsToUriString($inputUrl, ['variables' => ['text' => 'Lal$a', 'foo' => 'bar']]); + $result = (string) UriHelper::addOptionsToUriString($inputUrl, ['variables' => ['text' => 'Lal$a', 'foo' => 'bar']]); $exptected = 'https://test.rokka.io/stackname/v-foo-bar/b537639e539efcc3df4459ef87c5963aa5079ca6.jpg?foo=bar&baz&v=%7B%22text%22:%22Lal$a%22%7D'; $this->assertSame($exptected, $result); // without adding to v query - $result = (string) \Rokka\Client\UriHelper::addOptionsToUriString($inputUrl, ['variables' => ['text' => 'Lala', 'foo' => 'bar']]); + $result = (string) UriHelper::addOptionsToUriString($inputUrl, ['variables' => ['text' => 'Lala', 'foo' => 'bar']]); $exptected = 'https://test.rokka.io/stackname/v-foo-bar-text-Lala/b537639e539efcc3df4459ef87c5963aa5079ca6.jpg?foo=bar&baz'; $this->assertSame($exptected, $result); // with string as options - $result = (string) \Rokka\Client\UriHelper::addOptionsToUriString($inputUrl, 'v-a-b'); + $result = (string) UriHelper::addOptionsToUriString($inputUrl, 'v-a-b'); $exptected = 'https://test.rokka.io/stackname/v-a-b/b537639e539efcc3df4459ef87c5963aa5079ca6.jpg?foo=bar&baz'; $this->assertSame($exptected, $result); // with existing v query string $inputUrl = 'https://test.rokka.io/stackname/b537639e539efcc3df4459ef87c5963aa5079ca6.jpg?foo=bar&baz&v={"foo": "b%at"}'; - $result = (string) \Rokka\Client\UriHelper::addOptionsToUriString($inputUrl, ['variables' => ['text' => 'La#la', 'foo' => 'ba%r']]); + $result = (string) UriHelper::addOptionsToUriString($inputUrl, ['variables' => ['text' => 'La#la', 'foo' => 'ba%r']]); $exptected = 'https://test.rokka.io/stackname/b537639e539efcc3df4459ef87c5963aa5079ca6.jpg?foo=bar&baz&v=%7B%22foo%22:%22ba%25r%22,%22text%22:%22La%23la%22%7D'; $this->assertSame($exptected, $result); - - - } - private function twoRoutesTest(array $hashes, $stack, $option, array $expectedOptions) { foreach ($hashes as $hash) { @@ -232,16 +223,13 @@ private function singleRouteTest($testUrl, $hash, array $expectedOptions, $filen $this->assertEquals($filename, (string) $components['filename'], 'Filename was not as expected for url '.$testUrl); $this->assertEquals('jpeg', $components['format'], 'Format was not as expected for url '.$testUrl); $this->assertEquals($expectedOptions['optionsArray'], $cStack->getStackOptions(), 'Options were not as expected for url '.$testUrl); - //test back with composeUri + // test back with composeUri if ($filename) { $filename = '/'.$filename; } if ($expectedOptions['optionsUrl']) { - $expectedOptions['optionsUrl'] = $expectedOptions['optionsUrl'].'/'; + $expectedOptions['optionsUrl'] .= '/'; } $this->assertEquals('https://test.rokka.io/'.$stack.'/'.$expectedOptions['optionsUrl'].$hash.$filename.'.jpeg', (string) UriHelper::composeUri($components, $testUri)); } - - - }