LearnPAd/learnpad

View on GitHub
lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java

Summary

Maintainability
F
1 wk
Test Coverage

Method generateReducedNet has a Cognitive Complexity of 187 (exceeds 5 allowed). Consider refactoring.
Open

    public static PetriNet generateReducedNet(PetriNet pn) throws Exception{
        //FIXME: Riadattare la regola considerando gli arc weight!
        /* Applica regole piu complesse che generano una petri net minima (potrebbe renderne piu' difficile la lettura)
         Regole:
         - T1->P->T2 = posso togliere p ed unire le T (copiare tutti i next di T2 in T1 e i previous di T2 in T1 e rimuovere T2 e P) solo se p ha un solo next ed un solo previous e (T2 ha un solo previous o T1 ha un solo next): questa modalita riduce di piu gli stati ma in questo caso bisogna anche controllare che non esista una connessione tra un previous di t2 e t1. Se esiste non si puo applicare perche andrebbe a eliminare deadlock: Es: in questo caso non si puo ridurre: p0->t1->p->t2->p1, p0->t2

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

Method generateReducedNetLight has a Cognitive Complexity of 102 (exceeds 5 allowed). Consider refactoring.
Open

    public static PetriNet generateReducedNetLight(PetriNet pn) throws Exception{
        //FIXME: Riadattare la regola considerando gli arc weight!
        /* Applica regole piu leggere che non creano una petrinet minima
         Regole:
         - T1->P->T2 = posso togliere p ed unire le T (copiare tutti i next di T2 in T1 e rimuovere T2) solo se p ha un solo next ed un solo previous e T2 ha un solo previous

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

Method generateReducedNet has 115 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static PetriNet generateReducedNet(PetriNet pn) throws Exception{
        //FIXME: Riadattare la regola considerando gli arc weight!
        /* Applica regole piu complesse che generano una petri net minima (potrebbe renderne piu' difficile la lettura)
         Regole:
         - T1->P->T2 = posso togliere p ed unire le T (copiare tutti i next di T2 in T1 e i previous di T2 in T1 e rimuovere T2 e P) solo se p ha un solo next ed un solo previous e (T2 ha un solo previous o T1 ha un solo next): questa modalita riduce di piu gli stati ma in questo caso bisogna anche controllare che non esista una connessione tra un previous di t2 e t1. Se esiste non si puo applicare perche andrebbe a eliminare deadlock: Es: in questo caso non si puo ridurre: p0->t1->p->t2->p1, p0->t2

    Method generateReducedNetLight has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static PetriNet generateReducedNetLight(PetriNet pn) throws Exception{
            //FIXME: Riadattare la regola considerando gli arc weight!
            /* Applica regole piu leggere che non creano una petrinet minima
             Regole:
             - T1->P->T2 = posso togliere p ed unire le T (copiare tutti i next di T2 in T1 e rimuovere T2) solo se p ha un solo next ed un solo previous e T2 ha un solo previous

      Avoid deeply nested control flow statements.
      Open

                              for(PL t2PrevPlace: t2.previousList)
                                  if(!t2PrevPlace.equals(place))
                                      if(pnReduced.existConnection(t2PrevPlace, t1))
                                          canBeApplied=false;

        Avoid deeply nested control flow statements.
        Open

                                for(TR p1NextT: p1.nextList)
                                    if(!p1NextT.equals(transition))
                                        if(!pnReduced.existConnection(p2, p1NextT)){
                                            pnReduced.connect(p2, p1NextT);
                                            //System.out.println("Connect " + p2.name + " with " + p1NextT.name);

          Avoid deeply nested control flow statements.
          Open

                                  for(int j=i+1;j<plList.size();j++){                            
                                      if(plList.get(j).previousList.size()==1 
                                          && plList.get(j).nextList.size()==1
                                          && plList.get(i).previousList.get(0).equals(plList.get(j).previousList.get(0))
                                          && plList.get(i).nextList.get(0).equals(plList.get(j).nextList.get(0))){

            Avoid deeply nested control flow statements.
            Open

                                    for(int j=i+1;j<trList.size();j++){                            
                                        if(trList.get(j).previousList.size()==1 
                                            && trList.get(j).nextList.size()==1
                                            && trList.get(i).previousList.get(0).equals(trList.get(j).previousList.get(0))
                                            && trList.get(i).nextList.get(0).equals(trList.get(j).nextList.get(0))){

              Avoid deeply nested control flow statements.
              Open

                                      for(PL t2NextPlace: t2.nextList){
                                          if(!pnReduced.existConnection(t1, t2NextPlace)){
                                              pnReduced.connect(t1, t2NextPlace);
                                              //System.out.println("Connect " + t1.name + " with " + t2NextPlace.name);
                                          }

                Avoid deeply nested control flow statements.
                Open

                                        for(int j=i+1;j<plList.size();j++){                            
                                            if(plList.get(j).previousList.size()==1 
                                                && plList.get(j).nextList.size()==1
                                                && plList.get(i).previousList.get(0).equals(plList.get(j).previousList.get(0))
                                                && plList.get(i).nextList.get(0).equals(plList.get(j).nextList.get(0))){

                  Avoid deeply nested control flow statements.
                  Open

                                          for(TR p1PreviousTransition: p1.previousList)
                                              if(!pnReduced.existConnection(p1PreviousTransition, p2)){
                                                  pnReduced.connect(p1PreviousTransition, p2);
                                                  //System.out.println("Connect " + p1PreviousTransition.name + " with " + p2.name);
                                              }

                    Avoid deeply nested control flow statements.
                    Open

                                            if(!canBeApplied)
                                                continue;

                      Avoid deeply nested control flow statements.
                      Open

                                              for(PL t2NextPlace: t2.nextList){
                                                  if(!pnReduced.existConnection(t1, t2NextPlace)){
                                                      pnReduced.connect(t1, t2NextPlace);
                                                      //System.out.println("Connect " + t1.name + " with " + t2NextPlace.name);
                                                  }

                        Avoid deeply nested control flow statements.
                        Open

                                                for(int j=i+1;j<trList.size();j++){                            
                                                    if(trList.get(j).previousList.size()==1 
                                                        && trList.get(j).nextList.size()==1
                                                        && trList.get(i).previousList.get(0).equals(trList.get(j).previousList.get(0))
                                                        && trList.get(i).nextList.get(0).equals(trList.get(j).nextList.get(0))){

                          Avoid deeply nested control flow statements.
                          Open

                                                  for(PL t2PrevPlace: t2.previousList)
                                                      if(!t2PrevPlace.equals(place))
                                                          if(!pnReduced.existConnection(t2PrevPlace, t1)){
                                                              pnReduced.connect(t2PrevPlace, t1);
                                                              //System.out.println("Connect " + t2PrevPlace.name + " with " + t1.name);

                            Avoid deeply nested control flow statements.
                            Open

                                                    if(!canBeApplied)
                                                        continue;

                              Avoid deeply nested control flow statements.
                              Open

                                                      for(TR p2NextT: p2.nextList)
                                                          if(!p2NextT.equals(transition))
                                                              if(pnReduced.existConnection(p1, p2NextT))
                                                                  canBeApplied=false;

                                Avoid deeply nested control flow statements.
                                Open

                                                        for(TR p1PreviousTransition: p1.previousList)
                                                            if(!pnReduced.existConnection(p1PreviousTransition, p2)){
                                                                pnReduced.connect(p1PreviousTransition, p2);
                                                                //System.out.println("Connect " + p1PreviousTransition.name + " with " + p2.name);
                                                            }

                                  Method needToBeReduced has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public static boolean needToBeReduced(PetriNet pn) throws Exception{
                                          if(pn.isEmpty())
                                              throw new Exception("ERROR: The provided petri net is empty\nName:"+pn.getName());
                                          
                                          int numPlaceLimit = 100;

                                  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

                                  Similar blocks of code found in 4 locations. Consider refactoring.
                                  Open

                                              while(true){
                                                  boolean noMoreReductionsPTPE = true;
                                                  ArrayList<TR> trList = pnReduced.getTransitionList_safe();
                                                  for(int i=0;i<trList.size();i++){
                                                      if(trList.get(i).previousList.size()==1 && trList.get(i).nextList.size()==1){
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 174..195
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 276..297
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 300..321

                                  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 230.

                                  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

                                  Further Reading

                                  Similar blocks of code found in 4 locations. Consider refactoring.
                                  Open

                                              while(true){
                                                  boolean noMoreReductionsTPTE = true;
                                                  ArrayList<PL> plList = pnReduced.getPlaceList_safe();
                                                  for(int i=0;i<plList.size();i++){
                                                      if(plList.get(i).previousList.size()==1 && plList.get(i).nextList.size()==1){
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 150..171
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 276..297
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 300..321

                                  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 230.

                                  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

                                  Further Reading

                                  Similar blocks of code found in 4 locations. Consider refactoring.
                                  Open

                                              while(true){
                                                  boolean noMoreReductionsPTPE = true;
                                                  ArrayList<TR> trList = pnReduced.getTransitionList_safe();
                                                  for(int i=0;i<trList.size();i++){
                                                      if(trList.get(i).previousList.size()==1 && trList.get(i).nextList.size()==1){
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 150..171
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 174..195
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 300..321

                                  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 230.

                                  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

                                  Further Reading

                                  Similar blocks of code found in 4 locations. Consider refactoring.
                                  Open

                                              while(true){
                                                  boolean noMoreReductionsTPTE = true;
                                                  ArrayList<PL> plList = pnReduced.getPlaceList_safe();
                                                  for(int i=0;i<plList.size();i++){
                                                      if(plList.get(i).previousList.size()==1 && plList.get(i).nextList.size()==1){
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 150..171
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 174..195
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 276..297

                                  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 230.

                                  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

                                  Further Reading

                                  Identical blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                                          for(PL t2NextPlace: t2.nextList){
                                                              if(!pnReduced.existConnection(t1, t2NextPlace)){
                                                                  pnReduced.connect(t1, t2NextPlace);
                                                                  //System.out.println("Connect " + t1.name + " with " + t2NextPlace.name);
                                                              }
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 232..238

                                  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 48.

                                  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

                                  Further Reading

                                  Identical blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                                          for(PL t2NextPlace: t2.nextList){
                                                              if(!pnReduced.existConnection(t1, t2NextPlace)){
                                                                  pnReduced.connect(t1, t2NextPlace);
                                                                  //System.out.println("Connect " + t1.name + " with " + t2NextPlace.name);
                                                              }
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 83..89

                                  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 48.

                                  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

                                  Further Reading

                                  Identical blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                                          for(TR p1NextT: p1.nextList)
                                                              if(!p1NextT.equals(transition))
                                                                  if(!pnReduced.existConnection(p2, p1NextT)){
                                                                      pnReduced.connect(p2, p1NextT);
                                                                      //System.out.println("Connect " + p2.name + " with " + p1NextT.name);
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 91..96

                                  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 44.

                                  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

                                  Further Reading

                                  Identical blocks of code found in 2 locations. Consider refactoring.
                                  Open

                                                          for(PL t2PrevPlace: t2.previousList)
                                                              if(!t2PrevPlace.equals(place))
                                                                  if(!pnReduced.existConnection(t2PrevPlace, t1)){
                                                                      pnReduced.connect(t2PrevPlace, t1);
                                                                      //System.out.println("Connect " + t2PrevPlace.name + " with " + t1.name);
                                  lp-model-verification/verification-component-deadlock-plugin/src/main/java/eu/learnpad/verification/plugin/pn/algorithms/Algorithms.java on lines 131..136

                                  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 44.

                                  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

                                  Further Reading

                                  There are no issues that match your filters.

                                  Category
                                  Status