GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AwsUploadPolicy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 5
1
<?php
2
3
namespace Evoluta\DropzoneBundle\Manager;
4
5
class AwsUploadPolicy
6
{
7
    private $expireAt;
8
    private $bucket;
9
    private $acl;
10
    private $successStatus;
11
12
13
    private $base64Policy;
14
    private $signature;
15
16
17
    /**
18
     * @param $acl
19
     * @param $bucket
20
     * @param $expireAt
21
     * @param $successStatus
22
     */
23
    public function __construct($bucket, $secret, $acl = "public-read", $expireAt = "+1 hours", $successStatus = 201)
24
    {
25
        $this->acl = $acl;
26
        $this->bucket = $bucket;
27
        $this->expireAt = $expireAt;
28
        $this->successStatus = $successStatus;
29
30
        $policy = $this->generatePolicy();
31
        $this->base64Policy = base64_encode($policy);
32
        $this->signature = base64_encode(hash_hmac('sha1', $this->base64Policy, $secret, $raw_output = true));
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getSignature()
39
    {
40
        return $this->signature;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getBase64Policy()
47
    {
48
        return $this->base64Policy;
49
    }
50
51
    private function generatePolicy()
52
    {
53
        $jsonPolicy =  json_encode(
54
            array(
55
                'expiration' => date('Y-m-d\TG:i:s\Z', strtotime($this->expireAt)),
56
                'conditions' => array(
57
                    array(
58
                        'bucket' => $this->bucket,
59
                    ),
60
                    array(
61
                        'acl' => $this->acl,
62
                    ),
63
                    array(
64
                        'starts-with',
65
                        '$key',
66
                        '',
67
                    ),
68
                    array(
69
                        'success_action_status' => (string)$this->successStatus,
70
                    ),
71
                ),
72
            )
73
        );
74
        
75
        return $jsonPolicy;
76
    }
77
}
78