These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Gaufrette\Extras\Tests\Resolvable\Resolver; |
||
4 | |||
5 | use Aws\S3\S3Client; |
||
6 | |||
7 | /** |
||
8 | * @TODO: To be removed |
||
9 | * @see https://github.com/KnpLabs/Gaufrette/pull/494 |
||
10 | */ |
||
11 | trait AwsS3SetUpTearDownTrait |
||
12 | { |
||
13 | /** @var string */ |
||
14 | private $bucket; |
||
15 | |||
16 | /** @var S3Client */ |
||
17 | private $client; |
||
18 | |||
19 | public function setUp() |
||
20 | { |
||
21 | $key = getenv('AWS_KEY'); |
||
22 | $secret = getenv('AWS_SECRET'); |
||
23 | $region = getenv('AWS_REGION'); |
||
24 | |||
25 | if (empty($key) || empty($secret)) { |
||
26 | $this->markTestSkipped('Missing AWS_KEY and/or AWS_SECRET env vars.'); |
||
0 ignored issues
–
show
|
|||
27 | } |
||
28 | |||
29 | $this->bucket = uniqid(getenv('AWS_BUCKET')); |
||
30 | $this->client = new S3Client([ |
||
31 | 'region' => $region ? $region : 'eu-west-1', |
||
32 | 'version' => 'latest', |
||
33 | 'credentials' => [ |
||
34 | 'key' => $key, |
||
35 | 'secret' => $secret, |
||
36 | ], |
||
37 | ]); |
||
38 | } |
||
39 | |||
40 | public function tearDown() |
||
41 | { |
||
42 | if ($this->client === null || !$this->client->doesBucketExist($this->bucket)) { |
||
43 | return; |
||
44 | } |
||
45 | |||
46 | $result = $this->client->listObjects(['Bucket' => $this->bucket]); |
||
47 | $staleObjects = $result->get('Contents'); |
||
48 | |||
49 | foreach ($staleObjects as $staleObject) { |
||
50 | $this->client->deleteObject(['Bucket' => $this->bucket, 'Key' => $staleObject['Key']]); |
||
51 | } |
||
52 | |||
53 | $this->client->deleteBucket(['Bucket' => $this->bucket]); |
||
54 | } |
||
55 | } |
||
56 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.