Function parse_game_state_message
has a Cognitive Complexity of 279 (exceeds 5 allowed). Consider refactoring. Open
def parse_game_state_message(message, timestamp=None):
# DOM: ok
import app.mtga_app as mtga_app
with mtga_app.mtga_watch_app.game_lock: # the game state may become inconsistent in between these steps, so lock it
if "turnInfo" in message.keys():
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File parsers.py
has 661 lines of code (exceeds 250 allowed). Consider refactoring. Open
import json
import pprint
import datetime
import util
from app.models.game import Game, Match, Player
Function parse_zone
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
def parse_zone(zone_blob):
import app.mtga_app as mtga_app
trackable_zones = ["ZoneType_Hand", "ZoneType_Library", "ZoneType_Graveyard", "ZoneType_Exile", "ZoneType_Limbo",
"ZoneType_Stack", "ZoneType_Battlefield"]
zone_type = zone_blob["type"]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse_game_results
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def parse_game_results(_unused_locked, match_id, result_list):
import app.mtga_app as mtga_app
for idx, result in enumerate(result_list):
if not app.mtga_app.mtga_watch_app.match.has_results(idx):
# scope = result["scope"]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse_draft_status
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def parse_draft_status(blob):
# TODO: need to implement the sorting algo shown here:
# TODO: https://github.com/Fugiman/deckmaster/blob/559e3b94bb105387a0e33463e4b5f718ab91721d/client/updater.go#L113
""" return a.RarityRank() > b.RarityRank() ||
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function parse_match_playing
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def parse_match_playing(blob):
# MatchGameRoomStateType_Playing
import app.mtga_app as mtga_app
temp_players = {
1: {},
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function build_card_event_texts
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def build_card_event_texts(card, game):
if isinstance(card, Ability):
owner_is_hero = game.hero == game.get_player_in_seat(card.owner_seat_id)
text_type = "{}".format("hero" if owner_is_hero else "opponent")
ability_source = all_mtga_cards.find_one(card.source_id)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
for detail in details:
if detail['key'] == "orig_id":
original_id = detail["valueInt32"][0]
mtga_app.mtga_watch_app.game.ignored_iids.add(original_id)
# NOTE: at one point Spencer thought it might be correct to ignore these AFTER
Avoid deeply nested control flow statements. Open
for affected_id in affected_ids:
affected_texts = build_event_texts_from_iid_or_grpid(affected_id, mtga_app.mtga_watch_app.game)
target_texts.extend(affected_texts)
game_obj = mtga_app.mtga_watch_app.game.find_card_by_iid(affected_id)
target = game_obj if game_obj else affected_id
Avoid deeply nested control flow statements. Open
if isinstance(card, Ability):
# card resolutions are handled in annotations below
__unused_affected_ids = annotation["affectedIds"]
grpid = None
details = annotation["details"]
Avoid deeply nested control flow statements. Open
for attacker in attacker_list:
attacker_card = mtga_app.mtga_watch_app.game.find_card_by_iid(attacker)
limit_tuple = (mtga_app.mtga_watch_app.game.turn_number, "blocks", card, attacker_card)
if limit_tuple not in mtga_app.mtga_watch_app.game.recorded_targetspecs:
mtga_app.mtga_watch_app.game.recorded_targetspecs.append(limit_tuple)
Avoid deeply nested control flow statements. Open
if new_card_already_exists: # just wipe the old card, the new card is already there
assert new_card_already_exists.mtga_id == card_with_iid.mtga_id or -1 in [new_card_already_exists.mtga_id, card_with_iid.mtga_id], "{} / {}".format(new_card_already_exists.mtga_id , card_with_iid.mtga_id)
card_with_iid.mtga_id = -1
else:
card_with_iid.previous_iids.append(original_id)
Avoid deeply nested control flow statements. Open
if zone:
if not player:
player = mtga_app.mtga_watch_app.game.hero
# if zone is shared, don't care what player we use to put this card into it
assert isinstance(player, Player)
Avoid deeply nested control flow statements. Open
if app.mtga_app.mtga_watch_app.game.last_log_timestamp is None:
app.mtga_app.mtga_watch_app.game.last_log_timestamp = timestamp
app.mtga_app.mtga_watch_app.game.last_measured_timestamp = now
app.mtga_app.mtga_watch_app.game.log_start_time = timestamp
app.mtga_app.mtga_watch_app.game.last_decision_player = decisionPlayer
Avoid deeply nested control flow statements. Open
if affector_id == 0:
affector_id = card.owner_seat_id
player_texts = build_event_texts_from_iid_or_grpid(affector_id, mtga_app.mtga_watch_app.game)
Avoid deeply nested control flow statements. Open
if mtga_app.mtga_watch_app.intend_to_join_game_with:
new_hero.original_deck = mtga_app.mtga_watch_app.intend_to_join_game_with
new_match_id = match_id_raw + "-game{}-{}".format(game_number, new_hero.player_id)
mtga_app.mtga_watch_app.game = Game(new_match_id, new_hero, new_oppo, shared_battlefield,
shared_exile, shared_limbo, shared_stack,
Avoid deeply nested control flow statements. Open
if not card_with_iid: # no one has ref'd yet, we don't care
continue
new_card_already_exists = mtga_app.mtga_watch_app.game.find_card_by_iid(new_id)
Avoid deeply nested control flow statements. Open
if measured_time_diff > log_time_diff:
log_time_diff = measured_time_diff # some turns are really fast, and the logs see it as 0 seconds. Add what we measured instead,
Avoid deeply nested control flow statements. Open
for detail in details:
if detail["key"] == "zone_src":
zone_src = detail["valueInt32"][0]
if detail["key"] == "zone_dest":
zone_dest = detail["valueInt32"][0]
Avoid deeply nested control flow statements. Open
if category == "PlayLand":
event_texts = [*player_texts, " plays ", *annotation_texts]
queue_obj = {"game_history_event": event_texts}
mtga_app.mtga_watch_app.game.events.append(queue_obj["game_history_event"])
general_output_queue.put(queue_obj)
Avoid deeply nested control flow statements. Open
if not affector_card:
# try abilitiy
details = annotation["details"]
grpid = None
for detail in details:
Avoid deeply nested control flow statements. Open
if (affector_card, targets) not in mtga_app.mtga_watch_app.game.recorded_targetspecs:
mtga_app.mtga_watch_app.game.recorded_targetspecs.append((affector_card, targets))
affector_texts = build_card_event_texts(affector_card, mtga_app.mtga_watch_app.game)
event_texts = [*affector_texts, " targets "]
Avoid deeply nested control flow statements. Open
if card in zone.cards:
zone.cards.remove(card)
if message["type"] == "GameStateType_Diff" and "players" in message.keys():
Avoid deeply nested control flow statements. Open
if limit_tuple not in mtga_app.mtga_watch_app.game.recorded_targetspecs:
mtga_app.mtga_watch_app.game.recorded_targetspecs.append(limit_tuple)
card_texts = build_event_texts_from_iid_or_grpid(instance_id, mtga_app.mtga_watch_app.game)
event_texts = [*card_texts, " attacking"]
queue_obj = {"game_history_event": event_texts}
Avoid deeply nested control flow statements. Open
if "affectorId" not in annotation.keys():
affector_id = 0
else:
affector_id = annotation["affectorId"]
affected_ids = annotation["affectedIds"]
Avoid deeply nested control flow statements. Open
if message["turnInfo"]["turnNumber"] % 2 == 1:
app.mtga_app.mtga_watch_app.game.on_the_play = player.player_name
else:
app.mtga_app.mtga_watch_app.game.on_the_play = other_player.player_name
app.mtga_app.mtga_watch_app.game.current_phase = message["turnInfo"]["phase"]
Avoid deeply nested control flow statements. Open
if turn % 2 == 1:
text = "{} / {} Turn {}".format(turn, active_player.player_name, int((turn + 1) / 2))
else:
text = "{} / {} Turn {}".format(turn, active_player.player_name, int((turn / 2)))
text_obj = build_event_text(text, "turn")
Function parse_sideboard_submit
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def parse_sideboard_submit(blob):
import app.mtga_app as mtga_app
app.mtga_app.mtga_logger.info("{}".format(pprint.pformat(blob)))
og_deck_id = mtga_app.mtga_watch_app.intend_to_join_game_with.deck_id
og_deck_name = mtga_app.mtga_watch_app.intend_to_join_game_with.pool_name
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"