Passed
Push — master ( a07882...2b8759 )
by Thierry
02:21
created

File::extension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * File.php - This class represents an uploaded file.
5
 *
6
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2017 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
12
13
namespace Jaxon\Request\Upload;
14
15
class File
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class File
Loading history...
16
{
17
    /**
18
     * The uploaded file type
19
     *
20
     * @var string
21
     */
22
    protected $sType;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
23
24
    /**
25
     * The uploaded file name, without the extension and slugified
26
     *
27
     * @var string
28
     */
29
    protected $sName;
30
31
    /**
32
     * The uploaded file name, with the extension
33
     *
34
     * @var string
35
     */
36
    protected $sFilename;
37
38
    /**
39
     * The uploaded file path
40
     *
41
     * @var string
42
     */
43
    protected $sPath;
44
45
    /**
46
     * The uploaded file size
47
     *
48
     * @var string
49
     */
50
    protected $sSize;
51
52
    /**
53
     * The uploaded file extension
54
     *
55
     * @var string
56
     */
57
    protected $sExtension;
58
59
    /**
60
     * Slugify a text
61
     *
62
     * @param string  $sText
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
63
     *
64
     * @return string
65
     */
66
    protected static function slugify(string $sText): string
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
67
    {
68
        // Todo: slugify the text.
69
        return $sText;
70
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
71
72
    /**
73
     * Create an instance of this class using data from the $_FILES global var.
74
     *
75
     * @param string $sUploadDir    The directory where to save the uploaded file
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
76
     * @param array $aFile    The uploaded file data
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter name; 4 found
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
77
     *
78
     * @return File
79
     */
80
    public static function fromHttpData(string $sUploadDir, array $aFile): File
81
    {
82
        $xFile = new File();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
83
        $xFile->sType = $aFile['type'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
84
        $xFile->sName = self::slugify($aFile['filename']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
85
        $xFile->sFilename = $aFile['name'];
86
        $xFile->sExtension = $aFile['extension'];
87
        $xFile->sSize = $aFile['size'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
88
        $xFile->sPath = $sUploadDir . $xFile->sName . '.' . $xFile->sExtension;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
89
        return $xFile;
90
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
91
92
    /**
93
     * Create an instance of this class using data from an array.
94
     *
95
     * @param array $aFile    The uploaded file data
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
96
     *
97
     * @return File
98
     */
99
    public static function fromTempData(array $aFile): File
100
    {
101
        $xFile = new File();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
102
        $xFile->sType = $aFile['type'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
103
        $xFile->sName = $aFile['name'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
104
        $xFile->sFilename = $aFile['filename'];
105
        $xFile->sExtension = $aFile['extension'];
106
        $xFile->sSize = $aFile['size'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
107
        $xFile->sPath = $aFile['path'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
108
        return $xFile;
109
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
110
111
    /**
112
     * Convert the File instance to array.
113
     *
114
     * @return array<string,string>
115
     */
116
    public function toTempData(): array
117
    {
118
        return [
119
            'type' => $this->sType,
120
            'name' => $this->sName,
121
            'filename' => $this->sFilename,
122
            'extension' => $this->sExtension,
123
            'size' => $this->sSize,
124
            'path' => $this->sPath,
125
        ];
126
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
127
128
    /**
129
     * Get the uploaded file type
130
     *
131
     * @return string
132
     */
133
    public function type(): string
134
    {
135
        return $this->sType;
136
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
137
138
    /**
139
     * Get the uploaded file name, without the extension and slugified
140
     *
141
     * @return string
142
     */
143
    public function name(): string
144
    {
145
        return $this->sName;
146
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
147
148
    /**
149
     * Get the uploaded file name, with the extension
150
     *
151
     * @return string
152
     */
153
    public function filename(): string
154
    {
155
        return $this->sFilename;
156
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
157
158
    /**
159
     * Get the uploaded file path
160
     *
161
     * @return string
162
     */
163
    public function path(): string
164
    {
165
        return $this->sPath;
166
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
167
168
    /**
169
     * Get the uploaded file size
170
     *
171
     * @return string
172
     */
173
    public function size(): string
174
    {
175
        return $this->sSize;
176
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
177
178
    /**
179
     * Get the uploaded file extension
180
     *
181
     * @return string
182
     */
183
    public function extension(): string
184
    {
185
        return $this->sExtension;
186
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
187
}
188