Passed
Branch v1 (0c7460)
by Andrew
06:14
created

TranscoderVariable::getFileInfo()   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
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Transcoder plugin for Craft CMS 3.x
4
 *
5
 * Transcode videos to various formats, and provide thumbnails of the video
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\transcoder\variables;
12
13
use nystudio107\transcoder\Transcoder;
14
15
use craft\helpers\UrlHelper;
16
17
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
18
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 4
Loading history...
19
 * @package   Transcode
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
20
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 5
Loading history...
21
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
22
class TranscoderVariable
23
{
24
    // Public Methods
25
    // =========================================================================
26
27
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $videoOptions should have a doc-comment as per coding-style.
Loading history...
28
     * Returns a URL to the transcoded video or "" if it doesn't exist (at which
29
     * time it will create it).
30
     *
31
     * @param $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
32
     * @param $videoOptions
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
33
     *
34
     * @return string
35
     */
36
    public function getVideoUrl($filePath, $videoOptions): string
37
    {
38
        return Transcoder::$plugin->transcode->getVideoUrl($filePath, $videoOptions);
39
    }
40
41
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $thumbnailOptions should have a doc-comment as per coding-style.
Loading history...
42
     * Returns a URL to a video thumbnail
43
     *
44
     * @param $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
45
     * @param $thumbnailOptions
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
46
     *
47
     * @return string|false|null URL or path of the video thumbnail
48
     */
49
    public function getVideoThumbnailUrl($filePath, $thumbnailOptions)
50
    {
51
        return Transcoder::$plugin->transcode->getVideoThumbnailUrl($filePath, $thumbnailOptions);
52
    }
53
54
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $audioOptions should have a doc-comment as per coding-style.
Loading history...
55
     * Returns a URL to the transcoded audio file or "" if it doesn't exist
56
     * (at which time it will create it).
57
     *
58
     * @param $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
59
     * @param $audioOptions
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
60
     *
61
     * @return string
62
     */
63
    public function getAudioUrl($filePath, $audioOptions): string
64
    {
65
        return Transcoder::$plugin->transcode->getAudioUrl($filePath, $audioOptions);
66
    }
67
68
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
69
     * Extract information from a video/audio file
70
     *
71
     * @param      $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 6
Loading history...
72
     * @param bool $summary
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
73
     *
74
     * @return array
75
     */
76
    public function getFileInfo($filePath, $summary = false): array
77
    {
78
        return Transcoder::$plugin->transcode->getFileInfo($filePath, $summary);
79
    }
80
81
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $videoOptions should have a doc-comment as per coding-style.
Loading history...
82
     * Get a video progress URL
83
     *
84
     * @param $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
85
     * @param $videoOptions
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
86
     *
87
     * @return string
88
     */
89
    public function getVideoProgressUrl($filePath, $videoOptions): string
90
    {
91
        $result = '';
92
        $filename = Transcoder::$plugin->transcode->getVideoFilename($filePath, $videoOptions);
93
        if (!empty($filename)) {
94
            $urlParams = [
95
                'filename' => $filename,
96
            ];
97
            $result = UrlHelper::actionUrl('transcoder/default/progress', $urlParams);
98
        }
99
100
        return $result;
101
    }
102
103
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $audioOptions should have a doc-comment as per coding-style.
Loading history...
104
     * Get an audio progress URL
105
     *
106
     * @param $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
107
     * @param $audioOptions
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
108
     *
109
     * @return string
110
     */
111
    public function getAudioProgressUrl($filePath, $audioOptions): string
112
    {
113
        $result = '';
114
        $filename = Transcoder::$plugin->transcode->getAudioFilename($filePath, $audioOptions);
115
        if (!empty($filename)) {
116
            $urlParams = [
117
                'filename' => $filename,
118
            ];
119
            $result = UrlHelper::actionUrl('transcoder/default/progress', $urlParams);
120
        }
121
122
        return $result;
123
    }
124
125
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $gifOptions should have a doc-comment as per coding-style.
Loading history...
126
     * Get a GIF progress URL
127
     *
128
     * @param $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
129
     * @param $gifOptions
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
130
     *
131
     * @return string
132
     */
133
    public function getGifProgressUrl($filePath, $gifOptions): string
134
    {
135
        $result = '';
136
        $filename = Transcoder::$plugin->transcode->getGifFilename($filePath, $gifOptions);
137
        if (!empty($filename)) {
138
            $urlParams = [
139
                'filename' => $filename,
140
            ];
141
            $result = UrlHelper::actionUrl('transcoder/default/progress', $urlParams);
142
        }
143
144
        return $result;
145
    }
146
    
147
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $url should have a doc-comment as per coding-style.
Loading history...
148
     * Get a download URL
149
     *
150
     * @param $url
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
151
     *
152
     * @return string
153
     */
154
    public function getDownloadUrl($url): string
155
    {
156
        $result = '';
157
        $filePath = parse_url($url, PHP_URL_PATH);
158
        $filePath = $_SERVER['DOCUMENT_ROOT'] . $filePath;
159
        if (file_exists($filePath)) {
160
            $urlParams = [
161
                'url' => $url,
162
            ];
163
            $result = UrlHelper::actionUrl('transcoder/default/download-file', $urlParams);
164
        }
165
166
        return $result;
167
    }
168
    
169
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $filePath should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $gifOptions should have a doc-comment as per coding-style.
Loading history...
170
     * Returns a URL to a GIF file
171
     *
172
     * @param $filePath
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
173
     * @param $gifOptions
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
174
     *
175
     * @return string
176
     */
177
    public function getGifUrl($filePath, $gifOptions): string
178
    {
179
        return Transcoder::$plugin->transcode->getGifUrl($filePath, $gifOptions);
180
    }
181
}
182