src/index.js   A
last analyzed

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 47
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 6
mnd 3
bc 3
fnc 3
bpm 1
cpm 2
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
B Decorator.constructor 0 27 6
1
import { isClass, isFunction } from 'myrmidon';
2
import { mergeConfigs } from './utils';
3
import {
4
    FunctionDecorator,
5
    classMethodDecorator,
6
    classDecorator
7
} from  './decorators';
8
import defaultConfig from './defaults';
9
import { sanitizeRegexp } from './utils/sanitizers';
10
11
const dfc = [ defaultConfig ];
12
13
export class Decorator {
14
    constructor(...opts) {
15
        // eslint-disable-next-line no-constructor-return
16
        return (...args) => {
0 ignored issues
show
Bug introduced by
The constructor does not have a meaningful return value. Are you sure this is correct?
Loading history...
17
            const config = mergeConfigs(args, opts, dfc);
18
19
            return (target, methodName, descriptor) => {
20
                if (methodName && descriptor) {
21
                    return classMethodDecorator(
22
                        { target, methodName, descriptor },
23
                        config
24
                    );
25
                }
26
27
                if (isClass(target)) {
28
                    return classDecorator(target, config);
29
                }
30
31
                if (isFunction(target)) {
32
                    const functionDecorator = new FunctionDecorator({ config });
33
34
                    return functionDecorator.run(target);
35
                }
36
37
                throw new Error(`Can't decorate ${typeof target}, only functions, classes and class methods are allowed`);
38
            };
39
        };
40
    }
41
}
42
43
export default new Decorator();
44
45
export {
46
    sanitizeRegexp
47
};
48
49