AjaxController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A singleLibrary() 0 5 1
A files() 0 6 1
A contentTypeCache() 0 5 1
A __invoke() 0 3 1
A contentUserData() 0 3 1
A libraries() 0 24 2
A libraryUpload() 0 6 1
A libraryInstall() 0 5 1
A finish() 0 3 1
1
<?php
2
3
namespace Djoudi\LaravelH5p\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Djoudi\LaravelH5p\Events\H5pEvent;
7
use H5PEditorEndpoints;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\App;
10
use Log;
11
12
class AjaxController extends Controller
13
{
14
    public function libraries(Request $request)
15
    {
16
        $machineName = $request->get('machineName');
17
        $major_version = $request->get('majorVersion');
18
        $minor_version = $request->get('minorVersion');
19
20
        $h5p = App::make('LaravelH5p');
21
        $core = $h5p::$core;
0 ignored issues
show
Unused Code introduced by
The assignment to $core is dead and can be removed.
Loading history...
22
        $editor = $h5p::$h5peditor;
23
24
        //log($machineName);
25
        Log::debug('An informational message.'.$machineName.'====='.$h5p->get_language());
26
        if ($machineName) {
27
            $defaultLanguag = $editor->getLibraryLanguage($machineName, $major_version, $minor_version, $h5p->get_language());
28
            Log::debug('An informational message.'.$machineName.'====='.$h5p->get_language().'====='.$defaultLanguag);
29
30
            //   public function getLibraryData($machineName, $majorVersion, $minorVersion, $languageCode, $prefix = '', $fileDir = '', $defaultLanguage) {
31
32
            $editor->ajax->action(H5PEditorEndpoints::SINGLE_LIBRARY, $machineName, $major_version, $minor_version, $h5p->get_language(), '', $h5p->get_h5plibrary_url('', true), $defaultLanguag);  //$defaultLanguage
33
            // Log library load
34
            event(new H5pEvent('library', null, null, null, $machineName, $major_version.'.'.$minor_version));
35
        } else {
36
            // Otherwise retrieve all libraries
37
            $editor->ajax->action(H5PEditorEndpoints::LIBRARIES);
38
        }
39
    }
40
41
    public function singleLibrary(Request $request)
42
    {
43
        $h5p = App::make('LaravelH5p');
44
        $editor = $h5p::$h5peditor;
45
        $editor->ajax->action(H5PEditorEndpoints::SINGLE_LIBRARY, $request->get('_token'));
46
    }
47
48
    public function contentTypeCache(Request $request)
49
    {
50
        $h5p = App::make('LaravelH5p');
51
        $editor = $h5p::$h5peditor;
52
        $editor->ajax->action(H5PEditorEndpoints::CONTENT_TYPE_CACHE, $request->get('_token'));
53
    }
54
55
    public function libraryInstall(Request $request)
56
    {
57
        $h5p = App::make('LaravelH5p');
58
        $editor = $h5p::$h5peditor;
59
        $editor->ajax->action(H5PEditorEndpoints::LIBRARY_INSTALL, $request->get('_token'), $request->get('machineName'));
60
    }
61
62
    public function libraryUpload(Request $request)
63
    {
64
        $filePath = $request->file('h5p')->getPathName();
65
        $h5p = App::make('LaravelH5p');
66
        $editor = $h5p::$h5peditor;
67
        $editor->ajax->action(H5PEditorEndpoints::LIBRARY_UPLOAD, $request->get('_token'), $filePath, $request->get('contentId'));
68
    }
69
70
    public function files(Request $request)
71
    {
72
        $filePath = $request->file('file');
0 ignored issues
show
Unused Code introduced by
The assignment to $filePath is dead and can be removed.
Loading history...
73
        $h5p = App::make('LaravelH5p');
74
        $editor = $h5p::$h5peditor;
75
        $editor->ajax->action(H5PEditorEndpoints::FILES, $request->get('_token'), $request->get('contentId'));
76
    }
77
78
    public function __invoke(Request $request)
79
    {
80
        return response()->json($request->all());
81
    }
82
83
    public function finish(Request $request)
84
    {
85
        return response()->json($request->all());
86
    }
87
88
    public function contentUserData(Request $request)
89
    {
90
        return response()->json($request->all());
91
    }
92
}
93