1. Home
  2. Blog
  3. Custom Software

Custom Software

What Is Static Code Analysis and Quality Gates? Complexity, Thresholds and Findings Management Guide

What is static code analysis? Complexity math, quality gate thresholds, the new-code rule, false positives and finding debt, with worked examples.

Contents 14 sections
  1. What Is Static Code Analysis?
  2. What Is the Difference Between Static and Dynamic Analysis?
  3. What Findings Does Static Analysis Produce?
  4. How Is Cyclomatic Complexity Calculated?
  5. What Is a Quality Gate and Which Thresholds Do You Set?
  6. Why Should the Threshold Apply Only to New Code?
  7. Why Does the Coverage Rate Mislead?
  8. How Do You Manage False Positives and Set a Suppression Rule?
  9. How Do Old Findings Age and How Is the Debt Calculated?
  10. How Are Thresholds Calibrated?
  11. How Does the Quality Gate Connect to Continuous Integration and What Does It Cost?
  12. What Mistakes Are Common with Quality Gates?
  13. Custom Software and Process Quality with İnovabil
  14. Frequently Asked Questions

A development team can read every change line by line in code review, yet human eyes will not catch an unused variable, the third copy of the same block or a function with fifteen branches every single time. Static code analysis is the practice of scanning source code, without running it, to find that kind of problem automatically. A quality gate is the rule that looks at those findings and decides whether a change may be merged or not, based on thresholds.

In this guide we cover how static analysis differs from dynamic analysis, the types of findings, how cyclomatic complexity is calculated by hand, why quality gate thresholds should apply to new code only, the traps of coverage numbers, how to manage false positives, how to put a debt figure on old findings and how to wire the gate into continuous integration. Every example number is representative; none is the output of a specific tool or an industry average.

Key takeawayStatic analysis produces findings; it does not make decisions. The decision lives in the quality gate. The gate works best when it measures only the code written today, not the debt of old code: the team is pushed to write clean code every day, and the old debt is paid down as a separate, planned job. Apply the gate to the whole repository and either everyone is blocked from day one, or the threshold gets loosened until it stops nothing.

What Is Static Code Analysis?

Static code analysis is an automated review that reads source code without executing it and checks rules against its text and structure. The tool turns the code into a tree (a syntax tree) and looks for patterns such as unused variables, empty catch blocks, resources that are never closed, repeated blocks or deeply nested conditions. The result is a list of findings, each with a file and a line number.

Its strength is speed and consistency: it scans a hundred thousand lines in minutes, with the same rules every time, and never gets tired. Its weakness is that it does not know what the code will do at run time, so it reports some things that are not problems and misses some real defects. It does not replace human review; it reduces its load. We covered human review itself in our what is code review guide.

We recommend reading: Our custom software service

What Is the Difference Between Static and Dynamic Analysis?

Static analysis inspects the code without running it; dynamic analysis inspects it while it runs. They are complements, not competitors, and the table shows what each one can catch.

TopicStatic analysisDynamic analysis (tests, run-time monitoring)
When does it run?While code is written and on every changeWhile the application or a test runs
What does it look at?Code text and structureReal behavior and data
SpeedMinutes; no test environment neededSlower; needs an environment and data
Where it is strongStructural problems, inconsistencies, known unsafe patternsBusiness logic errors, performance, integration
Its blind spotCannot tell whether a business rule is right; produces false positivesIgnores paths that are never executed

In practice they are used together: static analysis is the cheap, early filter and tests confirm behavior. We worked out the economics of automated tests in our what is test automation article.

What Findings Does Static Analysis Produce?

Findings fall into four main types, and knowing the type decides how strictly the gate should treat each one.

TypeExampleTypical gate stance
BugAccess to a null value, unreachable code, a condition that is always trueNew bugs must be zero
VulnerabilityPutting unvalidated input into a query, a secret embedded in codeNew vulnerabilities must be zero
Code smellA very long function, too many parameters, deeply nested conditionsLimited by a threshold or a rating
DuplicationCopies of the same block in many placesDuplication rate in new code is capped

Security findings are also handled through the process in our secure software development guide; static analysis is one of that process's automated scanning steps. Code smells are the most visible form of technical debt.

How Is Cyclomatic Complexity Calculated?

Cyclomatic complexity is the number of independent paths through a function; in its simple form it is M = number of decision points + 1. Every condition, loop, and/or operator and ternary expression is a decision point. The order discount function below is representative.

  1. If the quantity is zero or less, return an error (1 decision).
  2. If the customer is blocked, return an error (2).
  3. If the customer tier is "A" (3) and the quantity is 100 or more (4; the second condition counts as a separate decision), give a 10% discount.
  4. Otherwise, if the tier is "B" (5), give a 5% discount.
  5. For each order line, loop (6); if the line is short of stock (7), add a warning.
  6. If a coupon exists, subtract its amount, otherwise use zero (ternary expression, 8).

There are 8 decision points, so M = 8 + 1 = 9. The practical meaning: to exercise every path through this function you need at least 9 test scenarios. Say the threshold is 10 (one commonly used reference value; each team picks its own): the function passes. When the business adds one more rule, M becomes 10, and with one more it becomes 11 and the gate asks for the function to be split.

Complexity is a testing and reading cost: as M grows, both the number of tests required and the likelihood of defects rise. Tools can count decision points differently, so choose the threshold from a baseline measured with the same tool.

What Is a Quality Gate and Which Thresholds Do You Set?

A quality gate is the list of criteria a change must pass before it merges. Each criterion has a threshold and a pass/fail result, and if a single one fails, the gate stays closed. Typical criteria are the number of new bugs and vulnerabilities, coverage of new code, the duplication rate and complexity per function.

Take a sample pull request (PR) with 400 new lines; 320 of them are executable lines and 272 are executed by tests. The results look like this.

Quality gate decision for a sample change: new-code coverage of 85 percent passes, duplication of 4.5 percent exceeds the threshold, three criteria fail
Gate decision for the sample change: not one criterion, all of them must pass.
CriterionValueThresholdResult
New bugs00Pass
New vulnerabilities10Fail
New-code coverage: 272 ÷ 32085.0%≥ 70%Pass
New-code duplication: 18 ÷ 4004.5%≤ 3%Fail
Most complex new functionM = 14≤ 10Fail

Three criteria fail, so the change does not merge. The good part is that feedback arrives on the day the code is written and is not personal.

Why Should the Threshold Apply Only to New Code?

Because old code is either not written by today's team or is waiting for a planned cleanup, and building the gate on it blocks every change unfairly. The new-code rule says: lines added and changed today must meet the threshold; lines that were not touched do not take part in the gate.

The arithmetic is plain. A repository has 120,000 lines, of which 60,000 are executable and 37,200 are covered by tests: overall coverage is 62.0%. If you put an 80% coverage gate on the whole repository, every change fails from the first day. Now suppose the team writes 10,000 new executable lines in the coming period and covers 80% of them (8,000). Overall coverage becomes (37,200 + 8,000) ÷ (60,000 + 10,000) = 45,200 ÷ 70,000 ≈ 64.6%. The overall figure moves only 2.6 points, yet every newly written line was disciplined. Old code gets diluted as new code grows and is cleaned wherever it is touched (the "boy scout rule": leave the place cleaner than you found it).

Old findings do not close the gate, but they are tracked in a separate list. The definition of "new code" comes from the lines compared against a branch or a reference version; we explained that comparison in our version control guide.

Why Does the Coverage Rate Mislead?

Coverage tells you which lines the tests execute; it does not tell you whether those lines were tested correctly. Three misunderstandings are common.

  • Line and branch coverage differ: The function above has 8 decision points with 2 outcomes each, 16 branch outcomes. If tests execute 11, branch coverage is 11 ÷ 16 ≈ 68.8%, while the same tests may execute 85% of the lines.
  • A test with no assertions covers but does not protect: It raises coverage and catches no defect.
  • A rate that becomes a target breaks: A more honest measure is mutation testing: small deliberate faults are injected and you count how many tests catch. Catching 14 of 20 gives a mutation score of 70%, the real protection even when line coverage is 90%.

So at the gate, coverage is only a floor safety (for example ≥ 70% on new code), not a quality goal.

How Do You Manage False Positives and Set a Suppression Rule?

A false positive is a finding the tool counts as a problem that is not one. If it is not managed, the team stops trusting findings and the tool loses its meaning. Measure first: if 200 findings from one week are reviewed by hand and 60 turn out to be wrong, the false positive rate is 60 ÷ 200 = 30%. If each review takes 4 minutes, the weekly loss is 60 × 4 = 240 minutes, that is 4 hours.

  • Track it per rule: The rate is per rule, not for the tool as a whole. If a rule has 20 findings and 18 are wrong (90%), the rule is tuned or demoted to a warning. Suggested threshold: if a rule's false rate exceeds 50% over at least 30 findings, it leaves the gate.
  • Suppression needs a reason: To suppress a finding, the line must state the reason, an owner and an end date (for example 90 days). The gate rejects a suppression without a reason.
  • Review suppressions: If 12 of 45 suppressions have expired, 12 ÷ 45 ≈ 26.7% have been left ownerless; a quarterly review takes 45 × 5 = 225 minutes (3.75 hours). Instead of suppressing the same false alarm again and again, fix the rule; that is the lasting solution.

How Do Old Findings Age and How Is the Debt Calculated?

The new-code rule does not make old findings disappear; it only stops them from growing. Old findings are a debt list, and they can be measured: estimate the average fix time for each finding type and multiply. In a representative repository, 1,800 old findings are distributed as follows.

TypeCountTime eachTotal
Bug4060 min2,400 min = 40 h
Vulnerability60120 min7,200 min = 120 h
Duplication50030 min15,000 min = 250 h
Code smell1,20015 min18,000 min = 300 h
Total1,80042,600 min = 710 h

710 hours at 8 hours a day is 88.75 working days; at ₺9,000 a day that is ₺798,750 (representative). You do not have to pay it all at once: bugs and vulnerabilities first, 40 + 120 = 160 hours, 20 working days, ₺180,000. If sprint capacity is 320 hours and 40 hours of it (12.5%) is set aside for debt, the priority list finishes in 160 ÷ 40 = 4 sprints. The remaining 550 hours erode slowly through the boy scout rule wherever code is touched.

Track aging too: a vulnerability older than 90 days turns red, a bug older than 180 days amber (example internal thresholds, not legal deadlines), and every finding needs an owner. See our technical debt guide and bug tracking article.

How Are Thresholds Calibrated?

A threshold is not an ideal number; it is today's reality plus a little. Take a four-week baseline measurement and set the threshold at a point most PRs will pass at first, then tighten it on a regular schedule. In representative data for 100 PRs, the effect of possible thresholds on new-code coverage looks like this.

Threshold (new-code coverage)PRs passing in month oneComment
≥ 90%38Too strict; the team looks for ways around the gate
≥ 80%64Can be the target; high friction if applied immediately
≥ 70%85Good as a start; rises by 5 points a quarter

The rule: start with a threshold that roughly 75–85% of PRs pass in the first month (here 70%), then raise it by 5 points a quarter to 75% and 80%. The same method works for complexity: if 36 of 300 functions (12%) have M > 10, the threshold of 10 is enforced on new code and the existing 36 functions enter the debt list. A threshold change is recorded too: who changed it, when, and based on which data.

How Does the Quality Gate Connect to Continuous Integration and What Does It Cost?

The gate should be a step that runs automatically when a change request is opened; a gate run by hand gets forgotten. It runs on the same pipeline as build and tests, the result shows on the change page, and the merge button stays locked until the gate passes. We described the pipeline itself in our CI/CD guide. If analysis time slows the pipeline, scan only the changed files and leave the full scan to the night.

Six steps of setting up a quality gate: scope, baseline measurement, rule selection, CI wiring, findings management, raising the threshold
The six steps of setting up a quality gate.
  1. Scope: Which repositories and languages; the definition of "new code" (which branch it is compared with).
  2. Baseline: Four weeks of data give the median and lower-quartile values.
  3. Rule selection: Few but clear rules; a noise budget (for example at most 3 warnings per PR) is written down.
  4. CI wiring: Automatic on every PR; a change that does not pass does not merge.
  5. Findings management: An owner, a due date and a suppression reason are mandatory.
  6. Raising the threshold: +5 points a quarter; a fixed share of sprint capacity for debt.

The cost (all representative): setup is 12 person-days × ₺9,000 = ₺108,000, running costs ₺6,000 a month. Of 100 PRs a month, 20 bounce off the gate and each needs 25 minutes: 500 minutes ≈ 8.33 hours ≈ ₺9,375 (₺1,125 an hour). If the gate catches 12 real bugs a month before merge, and a fix takes 0.5 hours in the PR but 10 hours in production with the incident, the benefit is 12 × 9.5 = 114 hours = ₺128,250. Monthly net: 128,250 − 9,375 − 6,000 = ₺112,875; payback is 108,000 ÷ 112,875 ≈ 1.0 month. If the benefit halves (₺64,125), net is ₺48,750 and payback about 2.2 months; recalculate with your own PR data.

Dependency scanning, which looks for vulnerabilities in the libraries you use, is a separate check covered in our software bill of materials guide; it can be added to the gate.

What Mistakes Are Common with Quality Gates?

  • Applying the gate to the whole repository: Everyone is blocked on day one; the gate gets loosened.
  • Turning on every rule: Noise buries real findings; start with few rules.
  • Suppressing without a reason and never updating the threshold: One creates a silent second debt list, the other makes the gate redundant.
  • Treating the tool as the only safeguard: A tool cannot know whether a business rule is right; review and tests stay in place.
We recommend reading: What is code review?

Custom Software and Process Quality with İnovabil

At İnovabil our focus is building company-specific software from scratch: custom software, ERP, CRM, e-commerce, web, mobile and integration. On every project we follow the steps recorded on our process page: analysis, design, development, testing, release, maintenance and support. Which automated checks and code quality rules apply to which project is settled in writing at the requirements stage, using the threshold and gate logic in this guide.

We built CRM, purchasing and mobile for Avcılar İnşaat; a purchasing system for İZBAN; logistics and shipment planning with wholesale order management for Karyak; and warehouse management with a complaint and support management system for Sleepy. Send us a short summary of your existing codebase or the project you are planning, with your quality and maintenance expectations, and we will assess it together.

We recommend reading: Our software development process: step by step from analysis to release

Frequently Asked Questions

What is static code analysis and what is it for?

It is a method that scans the text and structure of code without running it and automatically finds problems such as bugs, vulnerabilities, code smells and duplication. It is a fast, consistent first filter; it does not replace code review or tests.

What is a quality gate?

It is the set of criteria a change must pass before merging: the number of new bugs and vulnerabilities, new-code coverage, duplication rate, complexity per function and so on. Each criterion has a threshold, and if one fails the change does not merge.

Why should a quality gate measure only new code?

The debt in old code has nothing to do with today's change and would block every change unfairly. Setting thresholds only on new and changed lines stops new debt from accumulating, while old debt is paid down separately in a planned way.

What should cyclomatic complexity be?

There is no universal number; 10 per function is a commonly used reference value. It is computed as M = decision points + 1. Choose the threshold from your own baseline measurement and enforce it on new code.

Is code with high coverage high quality?

No. Coverage shows which lines tests execute, not whether they are tested correctly. Branch coverage and mutation score are more honest measures; at the gate, coverage serves only as a floor safety.

Let's talk about your project

Tell us briefly about the software you have in mind; we'll listen and prepare a tailored roadmap and proposal.

Get a quote