Skip to content

Commit 2a1c0e8

Browse files
committed
C#: Re-factor.
1 parent d882fe1 commit 2a1c0e8

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

csharp/ql/lib/semmle/code/csharp/frameworks/EntityFramework.qll

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ module EntityFramework {
339339
* Gets the string representation for synthetic identifiers for SaveChanges methods
340340
* on this.
341341
*/
342-
string getSyntheticNames() {
342+
private string getSyntheticNames() {
343343
exists(string qualifier, string type, string name |
344344
this.getASaveChanges().hasQualifiedName(qualifier, type, name)
345345
|
@@ -381,6 +381,17 @@ module EntityFramework {
381381
this.stepRev(tailHead, tailType, head, headType, dist)
382382
)
383383
}
384+
385+
pragma[nomagic]
386+
string getInputSynthetic(SummaryComponentStack output, DbContextClassSetProperty p) {
387+
exists(SummaryComponentStack synthetic, Property mapped |
388+
this = p.getDbContextClass() and
389+
input(this, synthetic, mapped) and
390+
output(this, output, mapped, p) and
391+
result =
392+
getFullSyntheticName(this.getSyntheticNames(), p.getSyntheticName(), synthetic, output)
393+
)
394+
}
384395
}
385396

386397
private class DbContextClassSetProperty extends Property {
@@ -454,12 +465,9 @@ module EntityFramework {
454465
override predicate propagatesFlow(
455466
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
456467
) {
457-
exists(SummaryComponentStack synthetic, string name, DbContextClass c, Property mapped |
468+
exists(string name, DbContextClass c |
458469
preservesValue = true and
459-
c = p.getDbContextClass() and
460-
input(c, synthetic, mapped) and
461-
output(c, output, mapped, p) and
462-
name = getFullSyntheticName(c.getSyntheticNames(), p.getSyntheticName(), synthetic, output) and
470+
name = c.getInputSynthetic(output, p) and
463471
input = SummaryComponentStack::syntheticGlobal(name)
464472
)
465473
}
@@ -478,18 +486,22 @@ module EntityFramework {
478486
)
479487
}
480488

489+
pragma[nomagic]
490+
string getOutputSynthetic(SummaryComponentStack input) {
491+
exists(SummaryComponentStack synthetic, Property mapped, DbContextClassSetProperty dbSet |
492+
input(c, input, mapped) and
493+
output(c, synthetic, mapped, dbSet) and
494+
result =
495+
getFullSyntheticName(this.getSyntheticName(), dbSet.getSyntheticName(), input, synthetic)
496+
)
497+
}
498+
481499
override predicate propagatesFlow(
482500
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue
483501
) {
484-
exists(
485-
SummaryComponentStack synthetic, string name, Property mapped,
486-
DbContextClassSetProperty dbSet
487-
|
502+
exists(string name |
488503
preservesValue = true and
489-
input(c, input, mapped) and
490-
output(c, synthetic, mapped, dbSet) and
491-
name =
492-
getFullSyntheticName(this.getSyntheticName(), dbSet.getSyntheticName(), input, synthetic) and
504+
name = this.getOutputSynthetic(input) and
493505
output = SummaryComponentStack::syntheticGlobal(name)
494506
)
495507
}
@@ -500,15 +512,8 @@ module EntityFramework {
500512
*/
501513
private class EFSummarizedCallableSyntheticGlobal extends SummaryComponent::SyntheticGlobal {
502514
EFSummarizedCallableSyntheticGlobal() {
503-
exists(
504-
DbContextClass c, SummaryComponentStack input, SummaryComponentStack output,
505-
Property mapped, DbContextClassSetProperty dbSet
506-
|
507-
input(c, input, mapped) and
508-
output(c, output, mapped, dbSet)
509-
|
510-
this = getFullSyntheticName(c.getSyntheticNames(), dbSet.getSyntheticName(), input, output)
511-
)
515+
this = any(DbContextClass c).getInputSynthetic(_, _) or
516+
this = any(DbContextSaveChanges c).getOutputSynthetic(_)
512517
}
513518
}
514519

0 commit comments

Comments
 (0)