diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 59114f6..7054c1a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -145,71 +145,21 @@ parameters: count: 1 path: test/functional/Resource/AccountTest.php - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\AccountTest\\:\\:testAccount\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/AccountTest.php - - message: "#^Call to an undefined method Seafile\\\\Client\\\\Type\\\\Library\\:\\:decrypt\\(\\)\\.$#" count: 1 path: test/functional/Resource/FileTest.php - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testCreate\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/FileTest.php - - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testHistory\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/FileTest.php - - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testList\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/FileTest.php - - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:testRename\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/FileTest.php - - - - message: "#^Property Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\FileTest\\:\\:\\$libraryResource \\(Seafile\\\\Client\\\\Resource\\\\Library\\|null\\) does not accept Seafile\\\\Client\\\\Type\\\\Library\\.$#" - count: 1 - path: test/functional/Resource/FileTest.php - - message: "#^Result of && is always false\\.$#" count: 1 path: test/functional/Resource/FileTest.php - - - message: "#^Strict comparison using \\=\\=\\= between string and true will always evaluate to false\\.$#" - count: 1 - path: test/functional/Resource/FileTest.php - - message: "#^Variable \\$cfg in isset\\(\\) is never defined\\.$#" count: 1 path: test/functional/Resource/FileTest.php - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\GroupTest\\:\\:testGetAll\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/GroupTest.php - - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\ShareLinksTest\\:\\:testShareLinks\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/ShareLinksTest.php - - - - message: "#^Method Seafile\\\\Client\\\\Tests\\\\Functional\\\\Resource\\\\StarredFileTest\\:\\:testStarFile\\(\\) has no return type specified\\.$#" - count: 1 - path: test/functional/Resource/StarredFileTest.php - - message: "#^Call to an undefined method PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\|Seafile\\\\Client\\\\Http\\\\Client\\:\\:expects\\(\\)\\.$#" count: 4 diff --git a/rector.php b/rector.php index 5c04965..a4e4135 100644 --- a/rector.php +++ b/rector.php @@ -2,7 +2,6 @@ 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; @@ -42,7 +41,6 @@ $rectorConfig->rules([ CountArrayToEmptyArrayComparisonRector::class, - DateFuncCallToCarbonRector::class, LongArrayToShortArrayRector::class, RenameVariableToMatchMethodCallReturnTypeRector::class, SymplifyQuoteEscapeRector::class, diff --git a/src/Type/Library.php b/src/Type/Library.php index 9a37392..f72a093 100644 --- a/src/Type/Library.php +++ b/src/Type/Library.php @@ -18,30 +18,11 @@ */ class Library extends Type { - /** - * @var string - */ - public $permission = ''; - - /** - * @var string - */ - public $encrypted = ''; - - /** - * @var string - */ - public $mtimeRelative = ''; - - /** - * @var DateTime - */ - public $mtime; - - /** - * @var string - */ - public $owner = ''; + public string $permission = ''; + public string $encrypted = ''; + public string $mtimeRelative = ''; + public DateTime $mtime; + public string $owner = ''; /** * @var string diff --git a/test/functional/FunctionalTestCase.php b/test/functional/FunctionalTestCase.php index 05a423d..6ab97ef 100644 --- a/test/functional/FunctionalTestCase.php +++ b/test/functional/FunctionalTestCase.php @@ -29,17 +29,10 @@ */ class FunctionalTestCase extends TestCase { - /** @var Client|null */ - protected $client; - - /** @var Logger|null */ - protected $logger; - - /** @var LibraryType|null */ - protected $testLib; - - /** @var Generator|null|Internet|Lorem|Person */ - protected $faker; + protected ?Client $client; + protected ?Logger $logger; + protected ?LibraryType $testLib; + protected Internet|Lorem|null|Generator|Person $faker; /** * Skip functional tests when they do not have been set up correctly. Please refer to README.md on how to set them up. @@ -132,7 +125,7 @@ protected function getTestLibraryType(): LibraryType $library = new Library($this->client); $this->testLib = $library->getById($libId); - if ($this->testLib->encrypted === true && array_key_exists('TEST_LIB_ENCRYPTED_PASSWORD', $_ENV)) { + if ($this->testLib->encrypted && array_key_exists('TEST_LIB_ENCRYPTED_PASSWORD', $_ENV)) { self::assertTrue($library->decrypt( $libId, [ diff --git a/test/functional/Resource/FileTest.php b/test/functional/Resource/FileTest.php index 229ba2f..eb1155b 100644 --- a/test/functional/Resource/FileTest.php +++ b/test/functional/Resource/FileTest.php @@ -2,12 +2,10 @@ namespace Seafile\Client\Tests\Functional\Resource; -use Carbon\Carbon; use Exception; use GuzzleHttp\Exception\GuzzleException; use Seafile\Client\Resource\Directory; use Seafile\Client\Resource\File; -use Seafile\Client\Resource\Library; use Seafile\Client\Tests\Functional\FunctionalTestCase; use Seafile\Client\Type\DirectoryItem; @@ -78,7 +76,7 @@ public function testHistory(): void $newFilename = tempnam($GLOBALS['BUILD_TMP'], 'Seafile-PHP-SDK_Test_File_History_Upload_'); rename($newFilename, $newFilename . '.txt'); $newFilename .= '.txt'; - file_put_contents($newFilename, 'Hello World: ' . Carbon::now()->format('Y-m-d H:i:s')); + file_put_contents($newFilename, 'Hello World: ' . (new \DateTime)->format('Y-m-d H:i:s')); $this->logger->debug("#################### Uploading file " . $newFilename); @@ -162,7 +160,7 @@ public function testRename(): void $libId = $_ENV['TEST_LIB_ENCRYPTED_ID']; $library = $this->getTestLibraryType(); - if ($library->encrypted === true && isset($cfg->testLibPassword)) { + if ($library->encrypted && isset($cfg->testLibPassword)) { $success = $this->library->decrypt($libId, ['query' => ['password' => $_ENV['TEST_LIB_ENCRYPTED_PASSWORD']]]); self::assertTrue($success); } @@ -176,7 +174,7 @@ public function testRename(): void $success = $this->file->create($library, $dirItem); self::assertTrue($success); - $newFilename = 'test_' . Carbon::now()->format('U') . '.txt'; + $newFilename = 'test_' . (new \DateTime)->format('U') . '.txt'; $dirItem = $this->file->getFileDetail($library, $path . $fileName); $this->logger->debug("#################### File to be renamed: " . $path . $dirItem->name); @@ -185,7 +183,7 @@ public function testRename(): void self::assertTrue($success); $this->logger->debug("#################### File renamed from " . $path . $fileName . ' to ' . $newFilename); - $newFilename = 'even_newer_file_name_test_' . Carbon::now()->format('U') . '.txt'; + $newFilename = 'even_newer_file_name_test_' . (new \DateTime)->format('U') . '.txt'; $success = $this->file->rename($library, $dirItem, $newFilename); self::assertTrue($success); diff --git a/test/functional/Resource/ShareLinksTest.php b/test/functional/Resource/ShareLinksTest.php index 6a68a9a..ed410c0 100644 --- a/test/functional/Resource/ShareLinksTest.php +++ b/test/functional/Resource/ShareLinksTest.php @@ -2,7 +2,6 @@ namespace Seafile\Client\Tests\Functional\Resource; -use Carbon\Carbon; use Exception; use Seafile\Client\Resource\File; use Seafile\Client\Resource\Library; @@ -43,6 +42,7 @@ protected function setUp(): void * and successfully so that's postponed for now. * * @throws Exception + * @throws \GuzzleHttp\Exception\GuzzleException */ public function testShareLinks(): void { @@ -68,7 +68,7 @@ public function testShareLinks(): void $newFilename = $GLOBALS['BUILD_TMP'] . '/Seafile-PHP-SDK_Test_Upload.txt'; if (!file_exists($newFilename)) { - file_put_contents($newFilename, 'Hello World: ' . Carbon::now()->format('Y-m-d H:i:s')); + file_put_contents($newFilename, 'Hello World: ' . (new \DateTime)->format('Y-m-d H:i:s')); } $this->logger->debug("#################### Uploading file " . $newFilename); diff --git a/test/unit/Resource/StarredFileTest.php b/test/unit/Resource/StarredFileTest.php index ebda192..b15ad49 100644 --- a/test/unit/Resource/StarredFileTest.php +++ b/test/unit/Resource/StarredFileTest.php @@ -105,8 +105,7 @@ public function testStar(): void ) // Return what was passed to offsetGet as a new instance ->will(self::returnCallback( - function ($method, $uri, array $params) use ($starResponse, $library, $directoryItem): Response|\Response { - + function ($method, $uri, array $params) use ($starResponse, $library, $directoryItem): Response { $hasParams = array_key_exists('headers', $params) && array_key_exists('multipart', $params) && array_key_exists('name', $params['multipart'][0]) diff --git a/test/unit/UnitTestCase.php b/test/unit/UnitTestCase.php index 6e4cacb..8317972 100644 --- a/test/unit/UnitTestCase.php +++ b/test/unit/UnitTestCase.php @@ -25,16 +25,15 @@ class UnitTestCase extends TestCase * * @param object $object Instantiated object that we will run method on. * @param string $methodName Method name to call - * @param array $parameters Array of parameters to pass into method. + * @param array|array $parameters Params to pass to method. * * @return mixed Method return. * @throws ReflectionException */ - public function invokeMethod(&$object, string $methodName, array $parameters = []) + public function invokeMethod(object &$object, string $methodName, array $parameters = []): mixed { $reflectionClass = new ReflectionClass($object::class); $reflectionMethod = $reflectionClass->getMethod($methodName); - $reflectionMethod->setAccessible(true); return $reflectionMethod->invokeArgs($object, $parameters); }