Completed
Push — 2.x ( 43b4ce...8d8edf )
by Frank
01:24 queued 10s
created

AwsS3V3AdapterTest::setting_acl_via_options()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Flysystem\AwsS3V3;
6
7
use Aws\Result;
8
use Aws\S3\S3Client;
9
use Aws\S3\S3ClientInterface;
10
use Exception;
11
use Generator;
12
use League\Flysystem\AdapterTestUtilities\FilesystemAdapterTestCase;
13
use League\Flysystem\Config;
14
use League\Flysystem\FileAttributes;
15
use League\Flysystem\FilesystemAdapter;
16
use League\Flysystem\PathPrefixer;
17
use League\Flysystem\StorageAttributes;
18
use League\Flysystem\UnableToCheckFileExistence;
19
use League\Flysystem\UnableToDeleteFile;
20
use League\Flysystem\UnableToMoveFile;
21
use League\Flysystem\UnableToRetrieveMetadata;
22
use League\Flysystem\UnableToWriteFile;
23
use RuntimeException;
24
25
use function getenv;
26
27
/**
28
 * @group aws
29
 */
30
class AwsS3V3AdapterTest extends FilesystemAdapterTestCase
31
{
32
    /**
33
     * @var bool
34
     */
35
    private $shouldCleanUp = false;
36
37
    /**
38
     * @var string
39
     */
40
    private static $adapterPrefix = 'test-prefix';
41
42
    /**
43
     * @var S3ClientInterface|null
44
     */
45
    private static $s3Client;
46
47
    /**
48
     * @var S3ClientStub
49
     */
50
    private static $stubS3Client;
51
52
    public static function setUpBeforeClass(): void
53
    {
54
        static::$adapterPrefix = getenv('FLYSYSTEM_AWS_S3_PREFIX') ?: 'ci/' . bin2hex(random_bytes(10));
0 ignored issues
show
Bug introduced by
Since $adapterPrefix is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $adapterPrefix to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
55
    }
56
57
    protected function tearDown(): void
58
    {
59
        if ( ! $this->shouldCleanUp) {
60
            return;
61
        }
62
63
        $adapter = $this->adapter();
64
        $adapter->deleteDirectory('/');
65
        /** @var StorageAttributes[] $listing */
66
        $listing = $adapter->listContents('', false);
67
68
        foreach ($listing as $item) {
69
            if ($item->isFile()) {
70
                $adapter->delete($item->path());
71
            } else {
72
                $adapter->deleteDirectory($item->path());
73
            }
74
        }
75
76
        self::$adapter = null;
77
    }
78
79
    private static function s3Client(): S3ClientInterface
80
    {
81
        if (static::$s3Client instanceof S3ClientInterface) {
0 ignored issues
show
Bug introduced by
Since $s3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $s3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
82
            return static::$s3Client;
0 ignored issues
show
Bug introduced by
Since $s3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $s3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
83
        }
84
85
        $key = getenv('FLYSYSTEM_AWS_S3_KEY');
86
        $secret = getenv('FLYSYSTEM_AWS_S3_SECRET');
87
        $bucket = getenv('FLYSYSTEM_AWS_S3_BUCKET');
88
        $region = getenv('FLYSYSTEM_AWS_S3_REGION') ?: 'eu-central-1';
89
90
        if ( ! $key || ! $secret || ! $bucket) {
91
            self::markTestSkipped('No AWS credentials present for testing.');
92
        }
93
94
        $options = ['version' => 'latest', 'credentials' => compact('key', 'secret'), 'region' => $region];
95
96
        return static::$s3Client = new S3Client($options);
0 ignored issues
show
Bug introduced by
Since $s3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $s3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
97
    }
98
99
    /**
100
     * @test
101
     */
102
    public function writing_with_a_specific_mime_type(): void
103
    {
104
        $adapter = $this->adapter();
105
        $adapter->write('some/path.txt', 'contents', new Config(['ContentType' => 'text/plain+special']));
106
        $mimeType = $adapter->mimeType('some/path.txt')->mimeType();
107
        $this->assertEquals('text/plain+special', $mimeType);
108
    }
109
110
    /**
111
     * @test
112
     */
113
    public function listing_contents_recursive(): void
114
    {
115
        $adapter = $this->adapter();
116
        $adapter->write('something/0/here.txt', 'contents', new Config());
117
        $adapter->write('something/1/also/here.txt', 'contents', new Config());
118
119
        $contents = iterator_to_array($adapter->listContents('', true));
120
121
        $this->assertCount(2, $contents);
122
        $this->assertContainsOnlyInstancesOf(FileAttributes::class, $contents);
123
        /** @var FileAttributes $file */
124
        $file = $contents[0];
125
        $this->assertEquals('something/0/here.txt', $file->path());
126
        /** @var FileAttributes $file */
127
        $file = $contents[1];
128
        $this->assertEquals('something/1/also/here.txt', $file->path());
129
    }
130
131
    /**
132
     * @test
133
     */
134 View Code Duplication
    public function failing_to_delete_while_moving(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
    {
136
        $adapter = $this->adapter();
137
        $adapter->write('source.txt', 'contents to be copied', new Config());
138
        static::$stubS3Client->failOnNextCopy();
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
139
140
        $this->expectException(UnableToMoveFile::class);
141
142
        $adapter->move('source.txt', 'destination.txt', new Config());
143
    }
144
145
    /**
146
     * @test
147
     */
148 View Code Duplication
    public function failing_to_write_a_file(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        $adapter = $this->adapter();
151
        static::$stubS3Client->throwDuringUpload(new RuntimeException('Oh no'));
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
152
153
        $this->expectException(UnableToWriteFile::class);
154
155
        $adapter->write('path.txt', 'contents', new Config());
156
    }
157
158
    /**
159
     * @test
160
     */
161
    public function failing_to_delete_a_file(): void
162
    {
163
        $adapter = $this->adapter();
164
        static::$stubS3Client->throwExceptionWhenExecutingCommand('DeleteObject');
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
165
166
        $this->expectException(UnableToDeleteFile::class);
167
168
        $adapter->delete('path.txt');
169
    }
170
171
    /**
172
     * @test
173
     */
174
    public function fetching_unknown_mime_type_of_a_file(): void
175
    {
176
        $this->adapter();
177
        $result = new Result([
178
            'Key' => static::$adapterPrefix . '/unknown-mime-type.md5',
0 ignored issues
show
Bug introduced by
Since $adapterPrefix is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $adapterPrefix to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
179
        ]);
180
        static::$stubS3Client->stageResultForCommand('HeadObject', $result);
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
181
182
        parent::fetching_unknown_mime_type_of_a_file();
183
    }
184
185
    /**
186
     * @test
187
     * @dataProvider dpFailingMetadataGetters
188
     */
189
    public function failing_to_retrieve_metadata(Exception $exception, string $getterName): void
190
    {
191
        $adapter = $this->adapter();
192
        $result = new Result([
193
             'Key' => static::$adapterPrefix . '/filename.txt',
0 ignored issues
show
Bug introduced by
Since $adapterPrefix is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $adapterPrefix to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
194
        ]);
195
        static::$stubS3Client->stageResultForCommand('HeadObject', $result);
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
196
197
        $this->expectExceptionObject($exception);
198
199
        $adapter->{$getterName}('filename.txt');
200
    }
201
202
    public function dpFailingMetadataGetters(): iterable
203
    {
204
        yield "mimeType" => [UnableToRetrieveMetadata::mimeType('filename.txt'), 'mimeType'];
205
        yield "lastModified" => [UnableToRetrieveMetadata::lastModified('filename.txt'), 'lastModified'];
206
        yield "fileSize" => [UnableToRetrieveMetadata::fileSize('filename.txt'), 'fileSize'];
207
    }
208
209
    /**
210
     * @test
211
     */
212
    public function failing_to_check_for_file_existence(): void
213
    {
214
        $adapter = $this->adapter();
215
216
        static::$stubS3Client->throw500ExceptionWhenExecutingCommand('HeadObject');
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
217
218
        $this->expectException(UnableToCheckFileExistence::class);
219
220
        $adapter->fileExists('something-that-does-exist.txt');
221
    }
222
223
    /**
224
     * @test
225
     * @dataProvider casesWhereHttpStreamingInfluencesSeekability
226
     */
227
    public function streaming_reads_are_not_seekable_and_non_streaming_are(bool $streaming, bool $seekable): void
228
    {
229
        if (getenv('COMPOSER_OPTS') === '--prefer-lowest') {
230
            $this->markTestSkipped('The SDK does not support streaming in low versions.');
231
        }
232
233
        $adapter = $this->useAdapter($this->createFilesystemAdapter($streaming));
234
        $this->givenWeHaveAnExistingFile('path.txt');
235
236
        $resource = $adapter->readStream('path.txt');
237
        $metadata = stream_get_meta_data($resource);
238
        fclose($resource);
239
240
        $this->assertEquals($seekable, $metadata['seekable']);
241
    }
242
243
    public function casesWhereHttpStreamingInfluencesSeekability(): Generator
244
    {
245
        yield "not streaming reads have seekable stream" => [false, true];
246
        yield "streaming reads have non-seekable stream" => [true, false];
247
    }
248
249
    /**
250
     * @test
251
     * @dataProvider casesWhereHttpStreamingInfluencesSeekability
252
     */
253
    public function configuring_http_streaming_via_options(bool $streaming): void
254
    {
255
        $adapter = $this->useAdapter($this->createFilesystemAdapter($streaming, ['@http' => ['stream' => false]]));
256
        $this->givenWeHaveAnExistingFile('path.txt');
257
258
        $resource = $adapter->readStream('path.txt');
259
        $metadata = stream_get_meta_data($resource);
260
        fclose($resource);
261
262
        $this->assertTrue($metadata['seekable']);
263
    }
264
265
    /**
266
     * @test
267
     */
268
    public function moving_with_updated_metadata(): void
269
    {
270
        $adapter = $this->adapter();
271
        $adapter->write('source.txt', 'contents to be moved', new Config(['ContentType' => 'text/plain']));
272
        $mimeTypeSource = $adapter->mimeType('source.txt')->mimeType();
273
        $this->assertSame('text/plain', $mimeTypeSource);
274
275
        $adapter->move('source.txt', 'destination.txt', new Config(
276
            ['ContentType' => 'text/plain+special', 'MetadataDirective' => 'REPLACE']
277
        ));
278
        $mimeTypeDestination = $adapter->mimeType('destination.txt')->mimeType();
279
        $this->assertSame('text/plain+special', $mimeTypeDestination);
280
    }
281
282
    /**
283
     * @test
284
     */
285
    public function setting_acl_via_options(): void
286
    {
287
        $adapter = $this->adapter();
288
        $prefixer = new PathPrefixer(static::$adapterPrefix);
0 ignored issues
show
Bug introduced by
Since $adapterPrefix is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $adapterPrefix to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
289
        $prefixedPath = $prefixer->prefixPath('path.txt');
290
291
        $adapter->write('path.txt', 'contents', new Config(['ACL' => 'bucket-owner-full-control']));
292
        $arguments = ['Bucket' => getenv('FLYSYSTEM_AWS_S3_BUCKET'), 'Key' => $prefixedPath];
293
        $command = static::$s3Client->getCommand('GetObjectAcl', $arguments);
0 ignored issues
show
Bug introduced by
Since $s3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $s3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
294
        $response = static::$s3Client->execute($command)->toArray();
0 ignored issues
show
Bug introduced by
Since $s3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $s3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
295
        $permission = $response['Grants'][0]['Permission'];
296
297
        self::assertEquals('FULL_CONTROL', $permission);
298
    }
299
300
    protected static function createFilesystemAdapter(bool $streaming = true, array $options = []): FilesystemAdapter
301
    {
302
        static::$stubS3Client = new S3ClientStub(static::s3Client());
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
Bug introduced by
Since s3Client() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of s3Client() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
303
        /** @var string $bucket */
304
        $bucket = getenv('FLYSYSTEM_AWS_S3_BUCKET');
305
        $prefix = static::$adapterPrefix;
0 ignored issues
show
Bug introduced by
Since $adapterPrefix is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $adapterPrefix to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
306
307
        return new AwsS3V3Adapter(static::$stubS3Client, $bucket, $prefix, null, null, $options, $streaming);
0 ignored issues
show
Bug introduced by
Since $stubS3Client is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $stubS3Client to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
308
    }
309
}
310