hannob / snallygaster

Tool to scan for secret files on HTTP servers
BSD Zero Clause License
2.07k stars 228 forks source link

reduce complexity and if block depth by using early exit #20

Closed hannob closed 4 years ago

hannob commented 6 years ago

Note to myself: in some functions we can reduce complexity and depth of if clauses by using earlier exits.

Example:

before

        if r.status == 200:
            if binary:
                return r.data
            return r.data.decode('ascii', errors='ignore')
        return ""

after


        if r.status != 200:
            return ""
        if binary:
            return r.data
        return r.data.decode('ascii', errors='ignore')
hannob commented 4 years ago

I only found this one instance where this is easily possible, fixed now: https://github.com/hannob/snallygaster/commit/573042daa7dd5255d8c4c487321315d3d749fa3b