Skip to content

Commit

Permalink
refactor: add typed on private property based on assigns (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 10, 2025
1 parent 110937b commit e761186
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 161 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"require": {
"php": ">=8.1",
"spiral/distribution": "^3.14.9",
"spiral/distribution": "^3.15",
"league/flysystem": "^2.3.1 || ^3.0"
},
"autoload": {
Expand All @@ -35,7 +35,7 @@
}
},
"require-dev": {
"spiral/boot": "^3.14.9",
"spiral/boot": "^3.15",
"phpunit/phpunit": "^10.1",
"vimeo/psalm": "^5.9",
"jetbrains/phpstorm-attributes": "^1.0",
Expand Down
11 changes: 5 additions & 6 deletions src/Bootloader/StorageBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public function init(BinderInterface $binder, EnvironmentInterface $env): void
$binder->bindSingleton(StorageInterface::class, static function (
BucketFactoryInterface $bucketFactory,
StorageConfig $config,
FactoryInterface $factory
) {
FactoryInterface $factory,
): StorageInterface {
$manager = new Storage($config->getDefaultBucket());

$distributions = $config->getDistributions();

foreach ($config->getAdapters() as $name => $adapter) {
Expand All @@ -73,10 +72,10 @@ public function init(BinderInterface $binder, EnvironmentInterface $env): void
return $manager;
});

$binder->bindSingleton(Storage::class, static fn (StorageInterface $manager) => $manager);
$binder->bindSingleton(Storage::class, static fn (StorageInterface $manager): StorageInterface => $manager);

$binder->bindSingleton(BucketInterface::class, static fn (StorageInterface $manager) => $manager->bucket());
$binder->bindSingleton(BucketInterface::class, static fn (StorageInterface $manager): BucketInterface => $manager->bucket());

$binder->bindSingleton(Bucket::class, static fn (BucketInterface $storage) => $storage);
$binder->bindSingleton(Bucket::class, static fn (BucketInterface $storage): BucketInterface => $storage);
}
}
2 changes: 1 addition & 1 deletion src/Bucket/ReadableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getLastModified(string $pathname): int;
/**
* Returns the file size in bytes.
*
* @return positive-int|0
* @return int<0, max>
* @throws FileOperationException
*/
public function getSize(string $pathname): int;
Expand Down
2 changes: 1 addition & 1 deletion src/Bucket/ReadableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getLastModified(string $pathname): int
}

/**
* @return positive-int|0
* @return int<0, max>
*/
public function getSize(string $pathname): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/File/ReadableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getLastModified(): int;
/**
* {@see BucketInterface::getSize()}
*
* @return positive-int|0
* @return int<0, max>
* @throws FileOperationException
*/
public function getSize(): int;
Expand Down
2 changes: 1 addition & 1 deletion src/File/ReadableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getLastModified(): int
}

/**
* @return positive-int|0
* @return int<0, max>
*/
public function getSize(): int
{
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/ReadableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function exists(string|\Stringable $id): bool;
/**
* {@see BucketInterface::getLastModified()}
*
* @return positive-int|0
* @return int<0, max>
* @throws FileOperationException
* @throws InvalidArgumentException
*/
Expand All @@ -54,7 +54,7 @@ public function getLastModified(string|\Stringable $id): int;
/**
* {@see BucketInterface::getSize()}
*
* @return positive-int|0
* @return int<0, max>
* @throws FileOperationException
* @throws InvalidArgumentException
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Storage/ReadableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function exists(string|\Stringable $id): bool
}

/**
* @return positive-int|0
* @return int<0, max>
*/
public function getLastModified(string|\Stringable $id): int
{
Expand All @@ -50,7 +50,7 @@ public function getLastModified(string|\Stringable $id): int
}

/**
* @return positive-int|0
* @return int<0, max>
*/
public function getSize(string|\Stringable $id): int
{
Expand Down
8 changes: 4 additions & 4 deletions tests/BucketFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function testCreatesBucketFromAdapter(): void
$name = 'foo',
);

$this->assertSame($name, $bucket->getName());
$this->assertNull($bucket->getUriResolver());
self::assertSame($name, $bucket->getName());
self::assertNull($bucket->getUriResolver());
}

public function testCreatesBucketFromAdapterWithResolver(): void
Expand All @@ -33,7 +33,7 @@ public function testCreatesBucketFromAdapterWithResolver(): void
$resolver = $this->createMock(UriResolverInterface::class)
);

$this->assertSame($name, $bucket->getName());
$this->assertSame($resolver, $bucket->getUriResolver());
self::assertSame($name, $bucket->getName());
self::assertSame($resolver, $bucket->getUriResolver());
}
}
22 changes: 11 additions & 11 deletions tests/Config/StorageConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function testGetDefaultBucket(): void
'default' => 'foo',
]);

$this->assertSame('foo', $config->getDefaultBucket());
self::assertSame('foo', $config->getDefaultBucket());
}

public function testS3Adapter(): void
{
$config = new StorageConfig($this->getConfig());

$this->assertEquals(new AwsS3V3Adapter(
self::assertEquals(new AwsS3V3Adapter(
new S3Client([
'version' => 'latest',
'region' => 'test-region',
Expand All @@ -53,7 +53,7 @@ public function testS3AsyncAdapter(): void
{
$config = new StorageConfig($this->getConfig());

$this->assertEquals(new AsyncAwsS3Adapter(
self::assertEquals(new AsyncAwsS3Adapter(
new S3AsyncClient([
'region' => 'test-region',
'endpoint' => 'test-endpoint',
Expand All @@ -73,7 +73,7 @@ public function testS3AdapterWithOverriddenBucket(): void
'uploads' => ['server' => 's3', 'bucket' => 'overridden']
]]));

$this->assertEquals(new AwsS3V3Adapter(
self::assertEquals(new AwsS3V3Adapter(
new S3Client([
'version' => 'latest',
'region' => 'test-region',
Expand All @@ -98,7 +98,7 @@ public function testS3AsyncAdapterWithOverriddenBucket(): void
'uploads-async' => ['server' => 's3-async', 'bucket' => 'overridden']
]]));

$this->assertEquals(new AsyncAwsS3Adapter(
self::assertEquals(new AsyncAwsS3Adapter(
new S3AsyncClient([
'region' => 'test-region',
'endpoint' => 'test-endpoint',
Expand All @@ -118,7 +118,7 @@ public function testS3AdapterWithOverriddenRegion(): void
'uploads' => ['server' => 's3', 'region' => 'overridden']
]]));

$this->assertEquals(new AwsS3V3Adapter(
self::assertEquals(new AwsS3V3Adapter(
new S3Client([
'version' => 'latest',
'region' => 'overridden',
Expand All @@ -143,7 +143,7 @@ public function testS3AsyncAdapterWithOverriddenRegion(): void
'uploads-async' => ['server' => 's3-async', 'region' => 'overridden']
]]));

$this->assertEquals(new AsyncAwsS3Adapter(
self::assertEquals(new AsyncAwsS3Adapter(
new S3AsyncClient([
'region' => 'overridden',
'endpoint' => 'test-endpoint',
Expand All @@ -163,7 +163,7 @@ public function testS3AdapterWithOverriddenVisibility(): void
'uploads' => ['server' => 's3', 'visibility' => Visibility::VISIBILITY_PRIVATE]
]]));

$this->assertEquals(new AwsS3V3Adapter(
self::assertEquals(new AwsS3V3Adapter(
new S3Client([
'version' => 'latest',
'region' => 'test-region',
Expand All @@ -188,7 +188,7 @@ public function testS3AsyncAdapterWithOverriddenVisibility(): void
'uploads-async' => ['server' => 's3-async', 'visibility' => Visibility::VISIBILITY_PRIVATE]
]]));

$this->assertEquals(new AsyncAwsS3Adapter(
self::assertEquals(new AsyncAwsS3Adapter(
new S3AsyncClient([
'region' => 'test-region',
'endpoint' => 'test-endpoint',
Expand All @@ -208,7 +208,7 @@ public function testS3AdapterWithOverriddenPrefix(): void
'uploads' => ['server' => 's3', 'prefix' => 'overridden']
]]));

$this->assertEquals(new AwsS3V3Adapter(
self::assertEquals(new AwsS3V3Adapter(
new S3Client([
'version' => 'latest',
'region' => 'test-region',
Expand All @@ -233,7 +233,7 @@ public function testS3AsyncAdapterWithOverriddenPrefix(): void
'uploads-async' => ['server' => 's3-async', 'prefix' => 'overridden']
]]));

$this->assertEquals(new AsyncAwsS3Adapter(
self::assertEquals(new AsyncAwsS3Adapter(
new S3AsyncClient([
'region' => 'test-region',
'endpoint' => 'test-endpoint',
Expand Down
Loading

0 comments on commit e761186

Please sign in to comment.