src/resources/assets/js/mixins/FormErrors.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 46
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
dl 0
loc 46
rs 10
c 1
b 0
f 0
cc 0
nc 1
mnd 1
bc 5
fnc 3
bpm 1.6666
cpm 2
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ???.data 0 10 1
A ???.methods.formatError 0 9 2
A ???.methods.hasError 0 7 3
1
export default {
2
    data: function () {
3
        return {
4
            /**
5
             * Form errors, keyed by field name.
6
             *
7
             * @type {Object}
8
             */
9
            errors: {},
10
        }
11
    },
12
13
    methods: {
14
        /**
15
         * Return true if field has error and is empty.
16
         *
17
         * @param  {String}  field
18
         *
19
         * @return {Boolean}
20
         */
21
        hasError (field) {
22
            if (field in this.errors && !this[field]) {
23
                return true;
24
            }
25
26
            return false;
27
        },
28
29
        /**
30
         * Format text block errors before display.
31
         *
32
         * @param  {String} error Error to format.
33
         *
34
         * @return {String}
35
         */
36
        formatError (error) {
37
            if (error.includes('.text')) {
38
                let errorArray = error.split('.');
39
40
                return 'The block ' + errorArray[2] + '.';
41
            }
42
43
            return error;
44
        }
45
    }
46
};