ZipFileDTO::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2018 Francois-Xavier Soubirou.
4
 *
5
 * This file is part of ci-report.
6
 *
7
 * ci-report is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * ci-report is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
declare(strict_types=1);
21
22
namespace App\DTO;
23
24
use JMS\Serializer\Annotation\Type;
25
use Symfony\Component\HttpFoundation\File\UploadedFile;
26
use Symfony\Component\HttpFoundation\Request;
27
use Symfony\Component\Validator\Constraints as Assert;
28
29
/**
30
 * Zip files data transfert object class.
31
 *
32
 * @category  ci-report app
33
 *
34
 * @author    Francois-Xavier Soubirou <[email protected]>
35
 * @copyright 2018 Francois-Xavier Soubirou
36
 * @license   http://www.gnu.org/licenses/   GPLv3
37
 *
38
 * @see      https://www.ci-report.io
39
 */
40
class ZipFileDTO
41
{
42
    /**
43
     * Zip file.
44
     *
45
     * @var UploadedFile
46
     *
47
     * @Type("UploadedFile")
48
     *
49
     * @Assert\NotBlank(
50
     *     message = "A zip file must be specified."
51
     * )
52
     * @Assert\File(
53
     *     maxSize = "4096k",
54
     *     mimeTypes = {"application/zip"},
55
     *     mimeTypesMessage = "Please upload a valid zip file"
56
     * )
57
     */
58
    protected $zipfile;
59
60
    /**
61
     * Constructor.
62
     *
63
     * @param Request $request
64
     */
65
    public function __construct(Request $request)
66
    {
67
        $file = $request->files->get('zipfile');
68
        if (null !== $file) {
69
            $this->setZipfile($file);
70
        }
71
    }
72
73
    /**
74
     * Set zip file.
75
     *
76
     * @param UploadedFile $file
77
     *
78
     * @return ZipFileDTO
79
     */
80
    public function setZipfile(UploadedFile $file): self
81
    {
82
        $this->zipfile = $file;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Get zip file.
89
     *
90
     * @return UploadedFile
91
     */
92
    public function getZipfile(): ?UploadedFile
93
    {
94
        return $this->zipfile;
95
    }
96
}
97