Completed
Push — master ( b5c7fa...23b509 )
by Taosikai
13:59
created

ExtensionConstraint   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 4 1
A getErrorMessage() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the slince/upload package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Slince\Upload\Constraint;
13
14
use Symfony\Component\HttpFoundation\File\UploadedFile;
15
16
class ExtensionConstraint implements ConstraintInterface
17
{
18
    /**
19
     * allowed extensions
20
     * @var array
21
     */
22
    protected $allowedExtensions = [];
23
24
    public function __construct(array $allowedExtensions)
25
    {
26
        $this->allowedExtensions = $allowedExtensions;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function validate(UploadedFile $file)
33
    {
34
        return in_array($file->getClientOriginalExtension(), $this->allowedExtensions);
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getErrorMessage(UploadedFile $file)
41
    {
42
        return sprintf('File extension "%s" is invalid', $file->getClientOriginalExtension());
43
    }
44
}