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

Order.ts ➔ Order   A

Complexity

Conditions 2

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 22
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.65
cc 2
crap 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