Passed
Push — main ( 2cd17f...238ec8 )
by Lorenzo
01:26 queued 16s
created

src/core/decorators/Order.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 28
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 18
mnd 1
bc 1
fnc 1
dl 0
loc 28
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A Order.ts ➔ Order 0 22 2
1 7
import { Executor } from '@/core/executor';
2
3
type AnyMethod = (...args: unknown[]) => unknown;
4
5
/**
6
 * Assigns an execution order to a method
7
 * @param order {number}
8
 * @decorator
9
 */
10 7
export function Order<This>(
11
  order: number,
12
) {
13 3
  return (
14
    method: AnyMethod,
15
    _context: ClassMethodDecoratorContext<This, AnyMethod>,
16
  ) => {
17 3
    Executor.setExecution('register', () => {
18 3
      const task = Executor.getTask(method);
19 3
      if (task) {
20 2
        task.order = order;
21
      } else {
22 1
        throw new Error('Method not registered for execution');
23
      }
24
    });
25 3
    return method;
26
  };
27
}
28