Passed
Push — depfu/update/npm/lodash-4.17.1... ( 152c97 )
by
unknown
04:58
created

WildPokemonItemComponent.remListItem   C

Complexity

Conditions 11

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 3
dl 0
loc 3
rs 5.4
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like WildPokemonItemComponent.remListItem often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import { ValueAccessorBase } from './../abstract/ValueAccessorBase';
2
/**
3
   Copyright 2018 June Hanabi
4
5
   Licensed under the Apache License, Version 2.0 (the "License");
6
   you may not use this file except in compliance with the License.
7
   You may obtain a copy of the License at
8
9
       http://www.apache.org/licenses/LICENSE-2.0
10
11
   Unless required by applicable law or agreed to in writing, software
12
   distributed under the License is distributed on an "AS IS" BASIS,
13
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
   See the License for the specific language governing permissions and
15
   limitations under the License.
16
 */
17
18
import { Component, EventEmitter, Output, Input, OnInit } from '@angular/core';
19
20
import {
21
    NG_VALUE_ACCESSOR,
22
} from '@angular/forms';
23
24
@Component({
25
    selector: 'wild-pokemon-item',
26
    templateUrl: './wild-pokemon-item.component.pug',
27
    styleUrls: ['./wild-pokemon-item.component.scss'],
28
    providers: [
29
        { provide: NG_VALUE_ACCESSOR, useExisting: WildPokemonItemComponent, multi: true }
30
    ],
31
})
32
export class WildPokemonItemComponent extends ValueAccessorBase<string> implements OnInit {
33
34
    constructor() {
35
        super();
36
    }
37
38
    ngOnInit() {
39
40
    }
41
42
    @Input()
43
    public disabled: boolean = false;
44
45
    @Input()
46
    public data: any = { id: 0, value: 1 };
47
48
    @Input()
49
    public index: number = 0;
50
51
    @Output()
52
    public remove: EventEmitter<boolean> = new EventEmitter();
53
54
    /*
55
     * The Pokemon list is in order from most common to most rare
56
     * Pokemon 0: 19.9% chance
57
     * Pokemon 1: 19.9% chance
58
     * Pokemon 2: 15.2% chance
59
     * Pokemon 3: 9.8% chance
60
     * Pokemon 4: 9.8% chance
61
     * Pokemon 5: 9.8% chance
62
     * Pokemon 6: 5.1% chance
63
     * Pokemon 7: 5.1% chance
64
     * Pokemon 8: 4.3% chance
65
     * Pokemon 9: 1.2% chance
66
     */
67
    get encounterChance() {
68
        if (this.index == 0)
69
            return "19.9%";
70
        else if (this.index == 1)
71
            return "19.9%";
72
        else if (this.index == 2)
73
            return "15.2%";
74
        else if (this.index == 3)
75
            return "9.8%";
76
        else if (this.index == 4)
77
            return "9.8%";
78
        else if (this.index == 5)
79
            return "9.8%";
80
        else if (this.index == 6)
81
            return "5.1%";
82
        else if (this.index == 7)
83
            return "5.1%";
84
        else if (this.index == 8)
85
            return "4.3%";
86
        else if (this.index == 9)
87
            return "1.2%";
88
89
        return "19.9%";
90
    }
91
92
    remListItem() {
93
        this.remove.emit(true);
94
    }
95
}
96