Completed
Push — master ( 506c79...7daaad )
by Julito
12:09
created

BaseController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 51
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A uploadAudioFile() 0 24 3
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\PluginBundle\WhispeakAuth\Controller;
5
6
use Chamilo\UserBundle\Entity\User;
7
use FFMpeg\FFMpeg;
8
use FFMpeg\Format\Audio\Wav;
9
10
/**
11
 * Class BaseController.
12
 *
13
 * @package Chamilo\PluginBundle\WhispeakAuth\Controller
14
 */
15
abstract class BaseController
16
{
17
    /**
18
     * @var \WhispeakAuthPlugin
19
     */
20
    protected $plugin;
21
22
    /**
23
     * BaseController constructor.
24
     */
25
    public function __construct()
26
    {
27
        $this->plugin = \WhispeakAuthPlugin::create();
28
    }
29
30
    /**
31
     * @param bool $isFullPage
32
     *
33
     * @return mixed
34
     */
35
    abstract protected function displayPage($isFullPage, array $variables);
36
37
    /**
38
     * @throws \Exception
39
     *
40
     * @return string
41
     */
42
    protected function uploadAudioFile(User $user)
43
    {
44
        $pluginName = $this->plugin->get_name();
45
46
        $path = api_upload_file($pluginName, $_FILES['audio'], $user->getId());
0 ignored issues
show
Deprecated Code introduced by
The function api_upload_file() has been deprecated: use Resources ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
        $path = /** @scrutinizer ignore-deprecated */ api_upload_file($pluginName, $_FILES['audio'], $user->getId());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47
48
        if (false === $path) {
49
            throw new \Exception(get_lang('UploadError'));
50
        }
51
52
        $fullPath = api_get_path(SYS_UPLOAD_PATH).$pluginName.$path['path_to_save'];
53
        $mimeType = mime_content_type($fullPath);
54
55
        if ('wav' !== substr($mimeType, -3)) {
56
            $ffmpeg = FFMpeg::create();
57
58
            $audioFile = $ffmpeg->open($fullPath);
59
60
            $fullPath = dirname($fullPath).'/audio.wav';
61
62
            $audioFile->save(new Wav(), $fullPath);
63
        }
64
65
        return $fullPath;
66
    }
67
}
68