S3ContextTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 61
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
getAwsServiceConfig() 0 1 ?
A getS3Client() 0 10 2
A getS3BucketFixture() 0 8 1
A getBucketName() 0 4 1
A createClaimCheckFactory() 0 4 1
1
<?php
2
3
namespace AbacaphiliacFeature\AwsSdk\ClaimCheck\Bootstrap\ContextTrait;
4
5
use Abacaphiliac\AwsSdk\ClaimCheck\ClaimCheckFactory;
6
use Aws\S3\S3Client;
7
8
trait S3ContextTrait
9
{
10
    /** @var  string */
11
    private $bucketName;
12
    
13
    /** @var  S3Client */
14
    private $s3Client;
15
16
    /**
17
     * @return mixed[]
18
     */
19
    abstract public function getAwsServiceConfig();
20
21
    /**
22
     * @return S3Client
23
     * @throws \InvalidArgumentException
24
     */
25
    public function getS3Client()
26
    {
27
        if (!$this->s3Client) {
28
            $config = $this->getAwsServiceConfig();
29
30
            $this->s3Client = new S3Client($config);
31
        }
32
33
        return $this->s3Client;
34
    }
35
36
    /**
37
     * @Given /^a data store named "([^"]*)"$/
38
     * @param string $name
39
     * @return string
40
     * @throws \InvalidArgumentException
41
     * @throws \Aws\S3\Exception\S3Exception
42
     * @throws \Exception
43
     */
44
    public function getS3BucketFixture($name)
45
    {
46
        $this->getS3Client()->headBucket(array(
47
            'Bucket' => $name,
48
        ));
49
        
50
        $this->bucketName = $name;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getBucketName()
57
    {
58
        return $this->bucketName;
59
    }
60
61
    /**
62
     * @return ClaimCheckFactory
63
     */
64
    public function createClaimCheckFactory()
65
    {
66
        return new ClaimCheckFactory($this->bucketName);
67
    }
68
}
69