Test Failed
Push — master ( a92e12...446184 )
by Domenico
04:27
created

S3ObjectSafeNameValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 21
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 14 3
1
<?php
2
/**
3
 *  This file is part of the Simple S3 package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Matecat\SimpleS3\Components\Validators;
13
14
/**
15
 * This class check if a string is a valid S3 object Name
16
 *
17
 * Amazon S3 object safe naming Requirements
18
 * -------------------------------------------------------------------------
19
 * You can use any UTF-8 character in an object key name. However, using certain characters in key names may cause problems with some applications and protocols.
20
 * The following guidelines help you maximize compliance with DNS, web-safe characters, XML parsers, and other APIs.
21
 *
22
 * Complete reference:
23
 *
24
 * https://docs.aws.amazon.com/en_us/AmazonS3/latest/dev/UsingMetadata.html
25
 *
26
 * @package SimpleS3
27
 */
28
final class S3ObjectSafeNameValidator extends S3NameValidator
29
{
30
    /**
31
     * @param string $string
32
     *
33
     * @return array
34
     */
35 13
    public static function validate($string)
36
    {
37 13
        $errors = [];
38
39 13
        if (substr($string, 0, 1) === '.') {
40 1
            $errors[] = 'The string cannot starts with .';
41
        }
42
43
        // check for string length
44 13
        if(strlen(urlencode($string)) > 221){
45 1
            $errors[] = 'The string is too long (max length of urlencoded string is 221 bytes)';
46
        }
47
48 13
        return $errors;
49
    }
50
}
51