Showing 283 of 283 total issues
Avoid deeply nested control flow statements. Open
if not form:
simpleForm = buildForm(simpleForm,
fields=[
{"var": "subject", "type": "text-single", "label": _("Subject"), "value": "Announcement"},
{"var": "body", "type": "text-multi", "label": _("Message"), "required": True},
Function sendInitPresence
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def sendInitPresence(self):
"""
Sends available presence to the user from all online friends
"""
if not self.vk.engine.captcha:
- 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
if not attachments and not chat:
message = [{"out": 0, "from_id": uid, "id": mid, "date": date, "text": body}]
# we substract 1 from msg id b/c VK now has reverse history so we need to ask what happened before this exact message
utils.runThread(user.sendMessages, (False, message, mid - 1, uid), "sendMessages-%s" % user.source)
Avoid deeply nested control flow statements. Open
if not form:
simpleForm = buildForm(simpleForm,
fields=[{"var": "jids", "type": "jid-multi", "label": _("Jabber ID's"), "required": True}])
else:
if dictForm.get("jids"):
Avoid deeply nested control flow statements. Open
if user.friends[id]["online"]:
sendPresence(source, destination, hash=USER_CAPS_HASH)
if destination == TransportID:
Avoid deeply nested control flow statements. Open
if jid != TransportID:
runDatabaseQuery("update groupchats set owner=? where jid=?", (source, jid), set=True)
Avoid deeply nested control flow statements. Open
if not phone or phone == "+":
result = utils.buildIQError(iq, xmpp.ERR_BAD_REQUEST, _("Phone is incorrect."))
else:
Avoid deeply nested control flow statements. Open
if status == MSG_SKIP:
for func in iter_:
utils.execute(func, (self, message))
break
elif status == MSG_APPEND:
Similar blocks of code found in 2 locations. Consider refactoring. Open
Protocol.__init__(self, "message", to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 35.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid deeply nested control flow statements. Open
if not item:
continue
messages.extend(item)
Avoid deeply nested control flow statements. Open
if not form:
_fields = dictToDataForm(dict([(mod, False) for mod in modules]))
if _fields:
simpleForm = buildForm(simpleForm, fields=_fields, title="Unload modules")
else:
Avoid deeply nested control flow statements. Open
if chat.isUpdateRequired():
updateLastUsed(chat)
raise xmpp.NodeProcessed()
Avoid deeply nested control flow statements. Open
if user.sendMessage(body, uID, mid=mid):
# check if the client requested the message to be marked as received
if msg.getTag("request", namespace=xmpp.NS_RECEIPTS):
answer = reportReceived(msg, jidFrom, jidTo)
if answer:
Identical blocks of code found in 2 locations. Consider refactoring. Open
hash = hashlib.sha1(owner.Dispatcher.Stream._document_attrs["id"] + self.password).hexdigest()
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 35.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid deeply nested control flow statements. Open
if not form:
simpleForm = buildForm(simpleForm,
fields=[{"var": "filename", "type": "list-single", "label": "Filename",
"options": os.listdir("crash") if os.path.exists("crash") else []}],
title="Choose wisely")
Avoid deeply nested control flow statements. Open
if not form:
simpleForm = buildForm(simpleForm, fields=getConfigFields(config), title="Choose wisely")
elif form:
for key in dictForm.keys():
Avoid deeply nested control flow statements. Open
if (time.gmtime().tm_mon, time.gmtime().tm_mday) == (4, 1):
setAffiliation(source, "outcast", jid, reason=_("Get the hell outta here!"))
else:
leaveChat(source, jid)
Avoid deeply nested control flow statements. Open
if text == "!captcha" and args:
acceptCaptcha(args, source, jidTo)
answer = reportReceived(msg, jidFrom, jidTo)
Avoid deeply nested control flow statements. Open
if x.isdigit():
text += x
else:
text += Nocolor + x
break
Avoid deeply nested control flow statements. Open
if self.settings.force_vk_date or init:
date = message["date"]
self.lastMsgByUser[frm] = mid