TranscoderVariable   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 161
Duplicated Lines 0 %

Importance

Changes 13
Bugs 0 Features 1
Metric Value
eloc 36
c 13
b 0
f 1
dl 0
loc 161
rs 10
wmc 13

9 Methods

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