Acl::setName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace EddTurtle\DirectUpload;
4
5
use EddTurtle\DirectUpload\Exceptions\InvalidAclException;
6
7
/**
8
 * Class Acl
9
 *
10
 * Acl is the AWS term for calculating the access of a file. This allows you to choose appropriate
11
 * permissions for a file by picking a possible acl.
12
 *
13
 * @package EddTurtle\DirectUpload
14
 */
15
class Acl
16
{
17
    // https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
18
    private $possibleOptions = [
19
        "authenticated-read",
20
        "aws-exec-read",
21
        "bucket-owner-full-control",
22
        "bucket-owner-read",
23
        "log-delivery-write",
24
        "private",
25
        "public-read",
26
        "public-read-write",
27
    ];
28
29
    /**
30
     * @var string
31
     */
32
    private $name;
33
34
    public function __construct(string $acl)
35
    {
36
        $this->setName($acl);
37
    }
38
39
    /**
40
     * @return string the aws acl policy name.
41
     */
42
    public function __toString()
43
    {
44
        return $this->getName();
45
    }
46
47
    /**
48
     * @param string $acl the aws acl policy name.
49
     *
50
     * @throws InvalidAclException
51
     */
52
    public function setName(string $acl): void
53
    {
54
        $acl = strtolower($acl);
55
        if (!in_array($acl, $this->possibleOptions)) {
56
            throw new InvalidAclException;
57
        }
58
        $this->name = $acl;
59
    }
60
61
    /**
62
     * @return string the aws acl policy name.
63
     */
64
    public function getName(): string
65
    {
66
        return $this->name;
67
    }
68
}
69