| Conditions | 24 | 
| Total Lines | 51 | 
| Code Lines | 50 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 1 | 
| CRAP Score | 563.3102 | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like build.match._match_ipv4_10() 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 | """Switch match."""  | 
            ||
| 37 | 1 | def _match_ipv4_10(match_fields, args, wildcards):  | 
            |
| 38 | """Match IPV4 fields against packet with Flow (OF1.0)."""  | 
            ||
| 39 | if not match_fields['eth_type'] == IPV4_ETH_TYPE:  | 
            ||
| 40 | return False  | 
            ||
| 41 |     flow_ip_int = int(ipaddress.IPv4Address(match_fields.get('ipv4_src'))) | 
            ||
| 42 | if flow_ip_int != 0:  | 
            ||
| 43 | mask = (wildcards  | 
            ||
| 44 | & FlowWildCards.OFPFW_NW_SRC_MASK) >> \  | 
            ||
| 45 | FlowWildCards.OFPFW_NW_SRC_SHIFT  | 
            ||
| 46 | if mask > 32:  | 
            ||
| 47 | mask = 32  | 
            ||
| 48 | if mask != 32 and 'ipv4_src' not in args:  | 
            ||
| 49 | return False  | 
            ||
| 50 | mask = (0xffffffff << mask) & 0xffffffff  | 
            ||
| 51 |         ip_int = int(ipaddress.IPv4Address(args.get('ipv4_src'))) | 
            ||
| 52 | if ip_int & mask != flow_ip_int & mask:  | 
            ||
| 53 | return False  | 
            ||
| 54 | flow_ip_int = int(ipaddress.IPv4Address(match_fields['ipv4_dst']))  | 
            ||
| 55 | if flow_ip_int != 0:  | 
            ||
| 56 | mask = (wildcards  | 
            ||
| 57 | & FlowWildCards.OFPFW_NW_DST_MASK) >> \  | 
            ||
| 58 | FlowWildCards.OFPFW_NW_DST_SHIFT  | 
            ||
| 59 | if mask > 32:  | 
            ||
| 60 | mask = 32  | 
            ||
| 61 | if mask != 32 and 'ipv4_dst' not in args:  | 
            ||
| 62 | return False  | 
            ||
| 63 | mask = (0xffffffff << mask) & 0xffffffff  | 
            ||
| 64 |         ip_int = int(ipaddress.IPv4Address(args.get('ipv4_dst'))) | 
            ||
| 65 | if ip_int & mask != flow_ip_int & mask:  | 
            ||
| 66 | return False  | 
            ||
| 67 | if not wildcards & FlowWildCards.OFPFW_NW_TOS:  | 
            ||
| 68 | if 'ip_tos' not in args:  | 
            ||
| 69 | return False  | 
            ||
| 70 |         if match_fields.get('ip_tos') != int(args.get('ip_tos')): | 
            ||
| 71 | return False  | 
            ||
| 72 | if not wildcards & FlowWildCards.OFPFW_NW_PROTO:  | 
            ||
| 73 | if 'ip_proto' not in args:  | 
            ||
| 74 | return False  | 
            ||
| 75 |         if match_fields.get('ip_proto') != int(args.get('ip_proto')): | 
            ||
| 76 | return False  | 
            ||
| 77 | if not wildcards & FlowWildCards.OFPFW_TP_SRC:  | 
            ||
| 78 | if 'tp_src' not in args:  | 
            ||
| 79 | return False  | 
            ||
| 80 |         if match_fields.get('tcp_src') != int(args.get('tp_src')): | 
            ||
| 81 | return False  | 
            ||
| 82 | if not wildcards & FlowWildCards.OFPFW_TP_DST:  | 
            ||
| 83 | if 'tp_dst' not in args:  | 
            ||
| 84 | return False  | 
            ||
| 85 |         if match_fields.get('tcp_dst') != int(args.get('tp_dst')): | 
            ||
| 86 | return False  | 
            ||
| 87 | return True  | 
            ||
| 88 | |||
| 174 |