SnsExtendedClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
ccs 4
cts 4
cp 1
nc 1
cc 1
eloc 3
nop 2
crap 1
1
<?php
2
3
namespace Abacaphiliac\AwsSdk\ClaimCheck\Sns;
4
5
use Abacaphiliac\AwsSdk\ClaimCheck\ClaimCheck;
6
use Abacaphiliac\AwsSdk\ClaimCheck\Exception\ExceptionInterface;
7
use Aws\Result;
8
use Aws\Sns\SnsClient;
9
use GuzzleHttp\Promise\Promise;
10
11
class SnsExtendedClient extends SnsClient
12
{
13
    /** @var  SnsClient */
14
    private $snsClient;
15
    
16
    /** @var  SnsExtendedClientConfiguration */
17
    private $configuration;
18
19
    /**
20
     * SnsExtendedClient constructor.
21
     * @param SnsClient $snsClient
22
     * @param SnsExtendedClientConfiguration $configuration
23
     */
24 1
    public function __construct(SnsClient $snsClient, SnsExtendedClientConfiguration $configuration)
25
    {
26 1
        $this->snsClient = $snsClient;
27 1
        $this->configuration = $configuration;
28 1
    }
29
30
    /**
31
     * @param string $name
32
     * @param mixed[] $args
33
     * @return Result|Promise
34
     * @throws ExceptionInterface
35
     */
36 1
    public function __call($name, array $args)
37
    {
38 1
        $params = array_key_exists(0, $args) ? $args[0] : [];
39
        
40 1
        if (strcasecmp($name, 'publish') === 0) {
41 1
            return $this->publishClaimCheck($params);
42
        }
43
        
44
        return $this->snsClient->{$name}($params);
45
    }
46
47
    /**
48
     * @param mixed[] $args
49
     * @return Result
50
     * @throws ExceptionInterface
51
     */
52 1 View Code Duplication
    private function publishClaimCheck(array $args = [])
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...
53
    {
54 1
        $claimCheckSerializer = $this->configuration->getClaimCheckSerializer();
55
56 1
        $message = array_key_exists('Message', $args) ? $args['Message'] : '';
57
58 1
        $claimCheck = $this->storeMessageInS3($message);
59
60 1
        $args['Message'] = $claimCheckSerializer->serialize($claimCheck);
61
62 1
        return $this->snsClient->publish($args);
63
    }
64
65
    /**
66
     * @param string $message
67
     * @return ClaimCheck
68
     */
69 1 View Code Duplication
    private function storeMessageInS3($message)
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...
70
    {
71 1
        $s3Client = $this->configuration->getS3Client();
72 1
        $s3BucketName = $this->configuration->getS3BucketName();
73 1
        $claimCheckFactory = $this->configuration->getClaimCheckFactory();
74
75 1
        $claimCheck = $claimCheckFactory->create();
76
77 1
        $s3Client->putObject([
78 1
            'Bucket' => $s3BucketName,
79 1
            'Key' => $claimCheck->getS3Key(),
80 1
            'Body' => $message,
81 1
        ]);
82
83 1
        return $claimCheck;
84
    }
85
}
86