Skip to content

Commit

Permalink
Merge pull request #80 from rokka-io/cs
Browse files Browse the repository at this point in the history
apply cs fixes
  • Loading branch information
dbu authored Jun 5, 2024
2 parents ee03fa3 + 248d3c6 commit 79aa5e5
Show file tree
Hide file tree
Showing 34 changed files with 137 additions and 161 deletions.
3 changes: 3 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$finder = PhpCsFixer\Finder::create()
->notPath('src/AppBundle/Command/TestCommand.php')
->exclude('tests/*/Fixtures')
Expand All @@ -10,6 +12,7 @@
$config = new PhpCsFixer\Config();

return $config
->setParallelConfig(ParallelConfigFactory::detect())
->setRiskyAllowed(true)
->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 @@ -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": {
Expand Down
8 changes: 6 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ parameters:
level: 7
paths:
- src/
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
ignoreErrors:
-
identifier: missingType.generics
-
identifier: missingType.iterableValue
2 changes: 1 addition & 1 deletion scripts/doctum-config.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Doctum\RemoteRepository\GitHubRemoteRepository;
use Doctum\Doctum;
use Doctum\RemoteRepository\GitHubRemoteRepository;
use Doctum\Version\GitVersionCollection;
use Symfony\Component\Finder\Finder;

Expand Down
3 changes: 3 additions & 0 deletions src/Core/DynamicMetadata/DetectionFace.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public static function getName()
return 'detection_face';
}

/**
* @return $this
*/
public function getForJson()
{
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DynamicMetadata/DynamicMetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function createFromDecodedJsonResponse($data);
/**
* Get the data, which should be json-fied later.
*
* @return mixed
* @return mixed The data that will be encoded to JSON
*/
public function getForJson();
}
3 changes: 3 additions & 0 deletions src/Core/DynamicMetadata/SubjectArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public static function getName()
return 'subject_area';
}

/**
* @return $this
*/
public function getForJson()
{
return $this;
Expand Down
7 changes: 4 additions & 3 deletions src/Core/DynamicMetadata/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ public static function getName()
*/
public static function createFromDecodedJsonResponse($data)
{
$object = new self($data['text']);

return $object;
return new self($data['text']);
}

/**
* @return self
*/
public function getForJson()
{
return $this;
Expand Down
34 changes: 15 additions & 19 deletions src/Core/SourceImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,20 @@ class SourceImage
public $locked;

/**
* Constructor.
*
* @param string $organization Organization
* @param string $binaryHash Binary hash
* @param string $hash Hash
* @param string $name Original name
* @param string $format Format
* @param int $size File size in bytes
* @param int $width Width in pixels
* @param int $height Height in pixels
* @param array $userMetadata User metadata
* @param array $dynamicMetadata Dynamic metadata
* @param \DateTime $created Created at date
* @param string $link Link to the image
* @param string $shortHash The short hash
* @param bool $protected Is image protected
* @param bool $locked Is image locked
* @param mixed $mimetype
* @param string $organization
* @param string $binaryHash
* @param string $hash
* @param string $name Original name
* @param string $format
* @param string $mimetype
* @param int $size File size in bytes
* @param int $width Width in pixels
* @param int $height Height in pixels
* @param \DateTime $created Created at date
* @param string $link Link to the image
* @param string $shortHash
* @param bool $protected
* @param bool $locked
*/
public function __construct(
$organization,
Expand Down Expand Up @@ -165,7 +161,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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/StackCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/StackUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Core/UriComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 57 in src/Core/UriComponents.php

View workflow job for this annotation

GitHub Actions / build

Invalid @param tag on "createFromArray": "array{stack: string, hash?: ?string, format?: ?string, filename?: ?string} $config" on "Rokka\Client\Core\UriComponents::createFromArray"

Check failure on line 57 in src/Core/UriComponents.php

View workflow job for this annotation

GitHub Actions / build

The "config" parameter of the method "createFromArray" is missing a @param tag on "Rokka\Client\Core\UriComponents::createFromArray"

Check failure on line 57 in src/Core/UriComponents.php

View workflow job for this annotation

GitHub Actions / build

The method "createFromArray" has "1" invalid @param tags. on "Rokka\Client\Core\UriComponents::createFromArray"
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/UserApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/UserApiToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct($token, $payload)
*
* @param array $resonse
*
* @return \Rokka\Client\Core\UserApiToken
* @return UserApiToken
*/
public static function createFromArray($resonse)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Factory
*
* @throws \RuntimeException
*
* @return Image
* @return ImageClient
*/
public static function getImageClient($organization, $apiKey, $options = [])
{
Expand Down Expand Up @@ -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) {
Expand Down
36 changes: 18 additions & 18 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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

Check failure on line 774 in src/Image.php

View workflow job for this annotation

GitHub Actions / build

Invalid @param tag on "addAutodescription": "array{force?: bool} $options if force is true, the description is generated again even if it already exists" on "Rokka\Client\Image::addAutodescription"

Check failure on line 774 in src/Image.php

View workflow job for this annotation

GitHub Actions / build

The method "addAutodescription" has "1" invalid @param tags. on "Rokka\Client\Image::addAutodescription"
{
Expand Down
12 changes: 6 additions & 6 deletions src/LocalImage/AbstractLocalImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -37,7 +37,7 @@ abstract class AbstractLocalImage
*
* @var string|null
*/
protected $identifier = null;
protected $identifier;

/**
* @since 1.3.0
Expand Down
6 changes: 3 additions & 3 deletions src/LocalImage/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/LocalImage/RokkaHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RokkaHash extends AbstractLocalImage
/**
* @var string|null
*/
private $content = null;
private $content;

/**
* @var TemplateHelper|null
Expand Down
4 changes: 2 additions & 2 deletions src/LocalImage/StringContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
* $image = new StringContent($content, $identifier, $context);
* ```
*
* @see \Rokka\Client\LocalImage\FileInfo
* @see FileInfo
* @since 1.3.0
*/
class StringContent extends AbstractLocalImage
{
/**
* @var string|null
*/
private $content = null;
private $content;

/**
* @param string|null $image
Expand Down
1 change: 1 addition & 0 deletions src/SearchHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading

0 comments on commit 79aa5e5

Please sign in to comment.