Skip to content

Commit

Permalink
fix: handle multiple classes in file
Browse files Browse the repository at this point in the history
Resolves: #92
  • Loading branch information
saschanowak committed Apr 30, 2024
1 parent c0588f7 commit b103770
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 56 deletions.
3 changes: 3 additions & 0 deletions __tests__/data/clover.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<class name="Netlogix\Nxdummy\Options\MiddlewareOptions" namespace="global">
<metrics complexity="5" methods="3" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="11" coveredstatements="10" elements="14" coveredelements="12"/>
</class>
<class name="Netlogix\Nxdummy\Options\MiddlewareOptions2" namespace="global">
<metrics complexity="5" methods="3" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="11" coveredstatements="10" elements="14" coveredelements="12"/>
</class>
<metrics loc="47" ncloc="47" classes="1" methods="3" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="11" coveredstatements="10" elements="14" coveredelements="12"/>
</file>
<file name="__tests__/data/nxdummy/Classes/Utility/UriUtility.php">
Expand Down
9 changes: 9 additions & 0 deletions __tests__/data/code-coverage-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
<td align="center">0.00%
<td align="right">0/1
<td align="center">➖
<tr>
<td>Netlogix\Nxdummy\Options\MiddlewareOptions2
<td align="center">90.91%
<td align="right">10/11
<td align="center">66.67%
<td align="right">2/3
<td align="center">0.00%
<td align="right">0/1
<td align="center">➖
<tr>
<td>Netlogix\Nxdummy\Utility\UriUtility
<td align="center">100.00%
Expand Down
48 changes: 25 additions & 23 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

70 changes: 38 additions & 32 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,41 +237,47 @@ export async function run(): Promise<{summary: string; details: string}> {
if (!file.hasOwnProperty('class')) {
continue
}
const statements = parseInt(file.class.metrics['@_statements'], 10)
const coveredstatements = parseInt(
file.class.metrics['@_coveredstatements'],
10
)

const covered =
parseInt(((coveredstatements / statements) * 100).toString(), 10) ===
100
? 1
: 0

packages[packageName].classes[file.class['@_name']] = {
name: file.class['@_name'],
classes: 1,
coveredclasses: covered,
complexity: parseInt(file.class.metrics['@_complexity'], 10),
loc: parseInt(file.class.metrics['@_loc'], 10),
ncloc: parseInt(file.class.metrics['@_ncloc'], 10),
methods: parseInt(file.class.metrics['@_methods'], 10),
coveredmethods: parseInt(file.class.metrics['@_coveredmethods'], 10),
conditionals: parseInt(file.class.metrics['@_conditionals'], 10),
coveredconditionals: parseInt(
file.class.metrics['@_coveredconditionals'],
const classes = !Array.isArray(file.class) ? [file.class] : file.class
for (const item of classes) {
const statements = parseInt(item.metrics['@_statements'], 10)
const coveredstatements = parseInt(
item.metrics['@_coveredstatements'],
10
),
statements: parseInt(file.class.metrics['@_statements'], 10),
coveredstatements: parseInt(
file.class.metrics['@_coveredstatements'],
10
),
elements: parseInt(file.class.metrics['@_elements'], 10),
coveredelements: parseInt(file.class.metrics['@_coveredelements'], 10)
)

const covered =
parseInt(
((coveredstatements / statements) * 100).toString(),
10
) === 100
? 1
: 0

packages[packageName].classes[item['@_name']] = {
name: item['@_name'],
classes: 1,
coveredclasses: covered,
complexity: parseInt(item.metrics['@_complexity'], 10),
loc: parseInt(item.metrics['@_loc'], 10),
ncloc: parseInt(item.metrics['@_ncloc'], 10),
methods: parseInt(item.metrics['@_methods'], 10),
coveredmethods: parseInt(item.metrics['@_coveredmethods'], 10),
conditionals: parseInt(item.metrics['@_conditionals'], 10),
coveredconditionals: parseInt(
item.metrics['@_coveredconditionals'],
10
),
statements: parseInt(item.metrics['@_statements'], 10),
coveredstatements: parseInt(
item.metrics['@_coveredstatements'],
10
),
elements: parseInt(item.metrics['@_elements'], 10),
coveredelements: parseInt(item.metrics['@_coveredelements'], 10)
}
packages[packageName].metrics.coveredclasses += covered
}
packages[packageName].metrics.coveredclasses += covered
}

const summaryMetric: SummaryMetric = {
Expand Down

0 comments on commit b103770

Please sign in to comment.