Skip to content

Commit

Permalink
chore: fixed many issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-s committed Jun 25, 2024
1 parent 32c700a commit 41c24a2
Show file tree
Hide file tree
Showing 47 changed files with 713 additions and 908 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"squizlabs/php_codesniffer": "~3.7",
"phpunit/php-timer": "~5.0",
"fzaninotto/faker": "~1.5",
"phpstan/phpstan": "^1.11"
"phpstan/phpstan": "^1.11",
"rector/rector": "^1.1"
},
"type": "library",
"autoload": {
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ parameters:
count: 1
path: src/Resource/File.php

-
message: "#^Parameter \\#2 \\$uri of method GuzzleHttp\\\\Client\\:\\:request\\(\\) expects Psr\\\\Http\\\\Message\\\\UriInterface\\|string, array\\<string\\>\\|string given\\.$#"
count: 1
path: src/Resource/File.php

-
message: "#^Method Seafile\\\\Client\\\\Resource\\\\Library\\:\\:decrypt\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -70,11 +65,6 @@ parameters:
count: 1
path: src/Resource/Multi.php

-
message: "#^PHPDoc tag @return with type mixed is not subtype of native type string\\.$#"
count: 1
path: src/Resource/Resource.php

-
message: "#^PHPDoc tag @return with type mixed is not subtype of native type string\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ includes:
- phpstan-baseline.neon

parameters:
level: 7
level: 7
58 changes: 58 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

use Rector\Carbon\Rector\FuncCall\DateFuncCallToCarbonRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector;
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector;
use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Symfony\Set\FOSRestSetList;
use Rector\Symfony\Set\SensiolabsSetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/test',
]);

$rectorConfig->phpVersion(PhpVersion::PHP_82);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::NAMING,
SetList::PRIVATIZATION,
SetList::STRICT_BOOLEANS,
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
FOSRestSetList::ANNOTATIONS_TO_ATTRIBUTES,
SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
SetList::TYPE_DECLARATION, // https://getrector.com/blog/new-in-rector-015-complete-safe-and-known-type-declarations
]);

$rectorConfig->rules([
CountArrayToEmptyArrayComparisonRector::class,
DateFuncCallToCarbonRector::class,
LongArrayToShortArrayRector::class,
RenameVariableToMatchMethodCallReturnTypeRector::class,
SymplifyQuoteEscapeRector::class,
ExceptionHandlerTypehintRector::class
]);

$rectorConfig->importNames();
$rectorConfig->autoloadPaths([
__DIR__ . '/vendor/autoload.php',
]);

$rectorConfig->parallel();
};
6 changes: 0 additions & 6 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public function __construct(array $config = [])

/**
* @param string|UriInterface $uri URI for request
* @param array $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function get($uri, array $options = []): ResponseInterface
Expand All @@ -54,8 +52,6 @@ public function get($uri, array $options = []): ResponseInterface

/**
* @param string|UriInterface $uri URI for request
* @param array $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function put($uri, array $options = []): ResponseInterface
Expand All @@ -65,8 +61,6 @@ public function put($uri, array $options = []): ResponseInterface

/**
* @param string|UriInterface $uri URI for request
* @param array $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function delete($uri, array $options = []): ResponseInterface
Expand Down
18 changes: 9 additions & 9 deletions src/Resource/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Seafile\Client\Resource;

use Exception;
use GuzzleHttp\Exception\GuzzleException;
use Seafile\Client\Type\Type;
use \Seafile\Client\Type\Account as AccountType;
use Seafile\Client\Type\TypeInterface;
Expand All @@ -18,7 +19,7 @@
*/
class Account extends Resource
{
const API_VERSION = '2';
public const API_VERSION = '2';

/**
* List accounts
Expand All @@ -27,6 +28,7 @@ class Account extends Resource
*
* @return AccountType[]
* @throws Exception
* @throws GuzzleException
*/
public function getAll(): array
{
Expand All @@ -50,8 +52,8 @@ public function getAll(): array
*
* @param string $emailAddress Email address
*
* @return AccountType
* @throws Exception
* @throws GuzzleException
*/
public function getByEmail(string $emailAddress): AccountType
{
Expand All @@ -71,8 +73,8 @@ public function getByEmail(string $emailAddress): AccountType
*
* @param string $emailAddress Email address to get info of
*
* @return AccountType|TypeInterface
* @throws Exception
* @throws GuzzleException
*/
public function getInfo(string $emailAddress): TypeInterface
{
Expand All @@ -93,8 +95,8 @@ public function getInfo(string $emailAddress): TypeInterface
*
* @param AccountType $accountType AccountType instance with data for new account
*
* @return bool
* @throws Exception
* @throws GuzzleException
*/
public function create(AccountType $accountType): bool
{
Expand Down Expand Up @@ -128,7 +130,6 @@ public function create(AccountType $accountType): bool
*
* @param AccountType $accountType AccountType instance with updated data
*
* @return bool
* @throws Exception
*/
public function update(AccountType $accountType): bool
Expand Down Expand Up @@ -212,8 +213,8 @@ public function update(AccountType $accountType): bool
*
* @param string $email Email address
*
* @return bool
* @throws Exception
* @throws GuzzleException
*/
public function removeByEmail(string $email): bool
{
Expand All @@ -226,12 +227,11 @@ public function removeByEmail(string $email): bool
* Requires admin permissions
*
* @param AccountType $accountType Account to remove
*
* @return bool
* @throws GuzzleException
*/
public function remove(AccountType $accountType): bool
{
if (empty($accountType->email)) {
if ($accountType->email === null || $accountType->email === '' || $accountType->email === '0') {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
*/
class Auth extends Resource implements ResourceInterface
{
const API_VERSION = '2';
public const API_VERSION = '2';
}
3 changes: 1 addition & 2 deletions src/Resource/Avatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getGroupAvatar(GroupType $groupType, int $size = 80)
*/
protected function getAvatar(Type $type, int $size)
{
if (!is_int($size) || $size < 1) {
if ($size < 1) {
throw new Exception('Illegal avatar size');
}

Expand Down Expand Up @@ -104,7 +104,6 @@ protected function getAvatar(Type $type, int $size)
*
* @param AccountType $accountType AccountType instance with data for new account
*
* @return bool
* @throws Exception
*/
public function createUserAvatar(AccountType $accountType): bool
Expand Down
49 changes: 22 additions & 27 deletions src/Resource/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
*/
class Directory extends Resource
{
const API_VERSION = '2';
public const API_VERSION = '2';

/**
* Get all items of a directory in a library
*
* @param LibraryType $library Library type
* @param LibraryType $libraryType Library type
* @param string $dir Directory path
*
* @return DirectoryItem[]
* @throws Exception
* @throws GuzzleException
*/
public function getAll(LibraryType $library, string $dir = '/')
public function getAll(LibraryType $libraryType, string $dir = '/'): array
{
$clippedBaseUri = $this->clipUri($this->getApiBaseUrl());

$response = $this->client->request(
'GET',
$clippedBaseUri . '/repos/' . $library->id . '/dir/',
$clippedBaseUri . '/repos/' . $libraryType->id . '/dir/',
[
'query' => ['p' => $dir],
]
Expand All @@ -63,17 +63,16 @@ public function getAll(LibraryType $library, string $dir = '/')
/**
* Check if $dirName exists within $parentDir
*
* @param LibraryType $library Library instance
* @param LibraryType $libraryType Library instance
* @param string $dirItemName DirectoryItem name
* @param string $parentDir Parent directory
*
* @return bool
* @throws Exception
* @throws GuzzleException
*/
public function exists(LibraryType $library, string $dirItemName, string $parentDir = '/')
public function exists(LibraryType $libraryType, string $dirItemName, string $parentDir = '/'): bool
{
$directoryItems = $this->getAll($library, $parentDir);
$directoryItems = $this->getAll($libraryType, $parentDir);

foreach ($directoryItems as $directoryItem) {
if ($directoryItem->name === $dirItemName) {
Expand All @@ -87,7 +86,7 @@ public function exists(LibraryType $library, string $dirItemName, string $parent
/**
* Create directory within $parentDir
*
* @param LibraryType $library Library instance
* @param LibraryType $libraryType Library instance
* @param string $dirName Directory name
* @param string $parentDir Parent directory
* @param bool $recursive Recursive create
Expand All @@ -96,7 +95,7 @@ public function exists(LibraryType $library, string $dirItemName, string $parent
* @throws Exception
* @throws GuzzleException
*/
public function create(LibraryType $library, string $dirName, string $parentDir = '/', bool $recursive = false)
public function create(LibraryType $libraryType, string $dirName, string $parentDir = '/', bool $recursive = false)
{
if ($recursive) {
$response = false;
Expand All @@ -107,28 +106,28 @@ public function create(LibraryType $library, string $dirName, string $parentDir
$parentPath = '/' . implode('/', $tmp);
$tmp[] = $part;

if ($this->exists($library, $part, $parentPath) === false) {
$response = $this->create($library, $part, $parentPath, false);
if ($this->exists($libraryType, $part, $parentPath) === false) {
$response = $this->create($libraryType, $part, $parentPath, false);
}
}

return $response;
}

// only create folder which is not empty to prevent wrong implementation
if (empty($dirName)) {
if ($dirName === '' || $dirName === '0') {
return false;
}

// Do not create folders that already exist
if ($this->exists($library, $dirName, $parentDir)) {
if ($this->exists($libraryType, $dirName, $parentDir)) {
return false;
}

$uri = sprintf(
'%s/repos/%s/dir/?p=%s/%s',
$this->clipUri($this->getApiBaseUrl()),
$library->id,
$libraryType->id,
rtrim($parentDir, '/'),
$dirName
);
Expand All @@ -153,22 +152,20 @@ public function create(LibraryType $library, string $dirName, string $parentDir
/**
* Remove a directory
*
* @param LibraryType $library Library instance
* @param LibraryType $libraryType Library instance
* @param string $directoryPath Directory path
*
* @return bool
*/
public function remove(LibraryType $library, string $directoryPath)
public function remove(LibraryType $libraryType, string $directoryPath): bool
{
// don't allow empty paths
if (empty($directoryPath)) {
if ($directoryPath === '' || $directoryPath === '0') {
return false;
}

$uri = sprintf(
'%s/repos/%s/dir/?p=%s',
$this->clipUri($this->getApiBaseUrl()),
$library->id,
$libraryType->id,
rtrim($directoryPath, '/')
);

Expand All @@ -186,23 +183,21 @@ public function remove(LibraryType $library, string $directoryPath)
/**
* Rename a directory
*
* @param LibraryType $library Library object
* @param LibraryType $libraryType Library object
* @param string $directoryPath Directory path
* @param string $newDirectoryName New directory name
*
* @return bool
*/
public function rename(LibraryType $library, string $directoryPath, string $newDirectoryName)
public function rename(LibraryType $libraryType, string $directoryPath, string $newDirectoryName): bool
{
// don't allow empty paths
if (empty($directoryPath) || empty($newDirectoryName)) {
if ($directoryPath === '' || $directoryPath === '0' || ($newDirectoryName === '' || $newDirectoryName === '0')) {
return false;
}

$uri = sprintf(
'%s/repos/%s/dir/?p=%s',
$this->clipUri($this->getApiBaseUrl()),
$library->id,
$libraryType->id,
rtrim($directoryPath, '/')
);

Expand Down
Loading

0 comments on commit 41c24a2

Please sign in to comment.