Completed
Pull Request — master (#90)
by Janis
15:10
created

js/temp/util.js   A

Complexity

Total Complexity 11
Complexity/F 1.83

Size

Lines of Code 58
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 58
rs 10
c 0
b 0
f 0
cc 0
nc 4
mnd 1
bc 9
fnc 6
bpm 1.5
cpm 1.8333
noi 6

1 Function

Rating   Name   Duplication   Size   Complexity  
B util.js ➔ Util 0 31 2
1
/**
2
 * nextCloud - ocr
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Janis Koehr <[email protected]>
8
 * @copyright Janis Koehr 2017
9
 */
10
(function (OC, OCA, window, $) {
0 ignored issues
show
Unused Code introduced by
The parameter $ is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
11
    'use strict';
12
    /**
13
     * Adds some util functions mainly used by the OCR controller.
14
     * @public
15
     * @class Ocr.Util
16
     */
17
    var Util = function (config) {
18
19
         /** Constructor */
20
        var ocrConfig;
21
        config !== undefined ? ocrConfig = config : console.error('OCR config is not defined.');
0 ignored issues
show
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
22
23
        /** TODO:
24
         * Filter file array for files with supported mimetypes and return 
25
         * the clean array of all input elements with a proper mimetype.
26
         * @public
27
         * @param {Array<File>} selectedFiles
28
         * @returns {Array<File>}
29
         */
30
        this.filterFilesWithMimeTypes = function (selectedFiles) {
31
			return selectedFiles.filter(function(file){
32
                return ocrConfig.ALLOWED_MIMETYPES.indexOf(file.mimetype) == -1 ? false : true;
0 ignored issues
show
Bug introduced by
The variable ocrConfig seems to not be initialized for all possible execution paths.
Loading history...
33
			});
34
		}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
35
36
        /** Reduce the input array of file elements to only contain the file id.
37
         * @public
38
         * @param {Array<File>} files
39
         * @returns {Array<File>}
40
         */
41
        this.shrinkData = function(files) {
42
			return files.map(function(file){
43
				return {id: file.id};
44
			});
45
		}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
46
47
    }
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
48
49
	/**
50
	 * Init OCR Util
51
	 */
52
    /** We have to be in the Files App! */
53
    if (!OCA.Files) {
54
        return;
55
    }
56
    /** Escape when the requested file is public.php */
57
    if (/(public)\.php/i.exec(window.location.href) !== null) {
58
        return;
59
    }
60
    /** Create namespace Ocr */
61
    if (!OCA.Ocr) {
62
        OCA.Ocr = {};
63
    }
64
    OCA.Ocr.Util = Util;
65
66
    /** global: OC, OCA */
67
})(OC, OCA, window, jQuery);
68