core/SanityTests.php

Summary

Maintainability
F
1 wk
Test Coverage

File SanityTests.php has 654 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/*
 * *****************************************************************************
 * Contributions to this work were made on behalf of the GÉANT project, a 
Severity: Major
Found in core/SanityTests.php - About 1 day to fix

    SanityTests has 28 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class SanityTests extends CAT
    {
        /* in this section set current CAT requirements */
    
        /**
    Severity: Minor
    Found in core/SanityTests.php - About 3 hrs to fix

      Function testDefaults has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          private function testDefaults()
          {
              $defaultvalues = "";
              $missingvalues = "";
              // all the checks for equality with a shipped default value
      Severity: Minor
      Found in core/SanityTests.php - About 3 hrs to fix

      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

      Function testDatabases has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          private function testDatabases()
          {
              $databaseName1 = 'INST';
              try {
                  $db1 = DBConnection::handle($databaseName1);
      Severity: Minor
      Found in core/SanityTests.php - About 2 hrs to fix

      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

      Function testDeviceCache has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          private function testDeviceCache()
          {
              if ((!empty(\devices\Devices::$Options['no_cache'])) && \devices\Devices::$Options['no_cache']) {
                  $global_no_cache = 1;
              } else {
      Severity: Minor
      Found in core/SanityTests.php - About 2 hrs to fix

      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 testGeoip has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function testGeoip()
          {
              $host_4 = '145.0.2.50';
              $host_6 = '2001:610:188:444::50';
              switch (\config\Master::GEOIP['version']) {
      Severity: Major
      Found in core/SanityTests.php - About 2 hrs to fix

        Method testDatabases has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function testDatabases()
            {
                $databaseName1 = 'INST';
                try {
                    $db1 = DBConnection::handle($databaseName1);
        Severity: Minor
        Found in core/SanityTests.php - About 1 hr to fix

          Function testGeoip has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              private function testGeoip()
              {
                  $host_4 = '145.0.2.50';
                  $host_6 = '2001:610:188:444::50';
                  switch (\config\Master::GEOIP['version']) {
          Severity: Minor
          Found in core/SanityTests.php - About 1 hr to fix

          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

          Function testPhpModules has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

              private function testPhpModules()
              {
                  if (function_exists('idn_to_ascii')) {
                      $this->storeTestResult(\core\common\Entity::L_OK, "PHP can handle internationalisation.");
                  } else {
          Severity: Minor
          Found in core/SanityTests.php - About 1 hr to fix

          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

          Function testMakensis has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              private function testMakensis()
              {
                  if (!is_numeric(\config\ConfAssistant::NSIS_VERSION)) {
                      $this->storeTestResult(\core\common\Entity::L_ERROR, "NSIS_VERSION needs to be numeric!");
                      return;
          Severity: Minor
          Found in core/SanityTests.php - About 1 hr to fix

          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 testPhpModules has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function testPhpModules()
              {
                  if (function_exists('idn_to_ascii')) {
                      $this->storeTestResult(\core\common\Entity::L_OK, "PHP can handle internationalisation.");
                  } else {
          Severity: Minor
          Found in core/SanityTests.php - About 1 hr to fix

            Method testDeviceCache has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function testDeviceCache()
                {
                    if ((!empty(\devices\Devices::$Options['no_cache'])) && \devices\Devices::$Options['no_cache']) {
                        $global_no_cache = 1;
                    } else {
            Severity: Minor
            Found in core/SanityTests.php - About 1 hr to fix

              Function __construct has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function __construct()
                  {
                      parent::__construct();
                      $this->test_result = [];
                      $this->test_result['global'] = 0;
              Severity: Minor
              Found in core/SanityTests.php - About 1 hr to fix

              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 testDirectories has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function testDirectories()
                  {
                      $Dir1 = \core\common\Entity::createTemporaryDirectory('installer', 0);
                      $dir1 = $Dir1['dir'];
                      $base1 = $Dir1['base'];
              Severity: Minor
              Found in core/SanityTests.php - About 1 hr to fix

                Method testDefaults has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function testDefaults()
                    {
                        $defaultvalues = "";
                        $missingvalues = "";
                        // all the checks for equality with a shipped default value
                Severity: Minor
                Found in core/SanityTests.php - About 1 hr to fix

                  Method testMakensis has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private function testMakensis()
                      {
                          if (!is_numeric(\config\ConfAssistant::NSIS_VERSION)) {
                              $this->storeTestResult(\core\common\Entity::L_ERROR, "NSIS_VERSION needs to be numeric!");
                              return;
                  Severity: Minor
                  Found in core/SanityTests.php - About 1 hr to fix

                    Function testNSISmodules has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function testNSISmodules()
                        {
                            $tmp_dir = \core\common\Entity::createTemporaryDirectory('installer', 0)['dir'];
                            if (!chdir($tmp_dir)) {
                                $this->loggerInstance->debug(2, "Cannot chdir to $tmp_dir\n");
                    Severity: Minor
                    Found in core/SanityTests.php - About 1 hr to fix

                    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 testNSISmodules has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function testNSISmodules()
                        {
                            $tmp_dir = \core\common\Entity::createTemporaryDirectory('installer', 0)['dir'];
                            if (!chdir($tmp_dir)) {
                                $this->loggerInstance->debug(2, "Cannot chdir to $tmp_dir\n");
                    Severity: Minor
                    Found in core/SanityTests.php - About 1 hr to fix

                      Method testMailer has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function testMailer()
                          {
                              if (empty(\config\Master::APPEARANCE['abuse-mail']) || \config\Master::APPEARANCE['abuse-mail'] == "my-abuse-contact@your-cat-installation.example") {
                                  $this->storeTestResult(\core\common\Entity::L_ERROR, "Your abuse-mail has not been set, cannot continue with mailer tests.");
                                  return;
                      Severity: Minor
                      Found in core/SanityTests.php - About 1 hr to fix

                        Function runTests has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function runTests($Tests)
                            {
                                foreach ($Tests as $testName) {
                                    $matchArray = [];
                                    if (preg_match('/(.+)=>(.+)/', $testName, $matchArray)) {
                        Severity: Minor
                        Found in core/SanityTests.php - About 55 mins to fix

                        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

                        Function getExecPath has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            private function getExecPath($pathToCheck)
                            {
                                $the_path = "";
                                $exec_is = "UNDEFINED";
                        
                        
                        Severity: Minor
                        Found in core/SanityTests.php - About 35 mins to fix

                        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

                        Avoid too many return statements within this method.
                        Open

                                            return;
                        Severity: Major
                        Found in core/SanityTests.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                              return;
                          Severity: Major
                          Found in core/SanityTests.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return;
                            Severity: Major
                            Found in core/SanityTests.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                                  return;
                              Severity: Major
                              Found in core/SanityTests.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                    return;
                                Severity: Major
                                Found in core/SanityTests.php - About 30 mins to fix

                                  Function testSsp has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      private function testSsp()
                                      {
                                          if (!is_file(\config\Master::AUTHENTICATION['ssp-path-to-autoloader'])) {
                                              $this->storeTestResult(\core\common\Entity::L_ERROR, "<strong>simpleSAMLphp</strong> not found!");
                                          } else {
                                  Severity: Minor
                                  Found in core/SanityTests.php - About 25 mins to fix

                                  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

                                  Function testDirectories has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      private function testDirectories()
                                      {
                                          $Dir1 = \core\common\Entity::createTemporaryDirectory('installer', 0);
                                          $dir1 = $Dir1['dir'];
                                          $base1 = $Dir1['base'];
                                  Severity: Minor
                                  Found in core/SanityTests.php - About 25 mins to fix

                                  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 2 locations. Consider refactoring.
                                  Open

                                          try {
                                              $db2 = DBConnection::handle($databaseName2);
                                              if (\config\ConfAssistant::CONSORTIUM['name'] == "eduroam" && isset(\config\ConfAssistant::CONSORTIUM['deployment-voodoo']) && \config\ConfAssistant::CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
                                                  $res2 = $db2->exec('desc view_admin');
                                                  if ($res2->num_rows == $this->viewAdminCount) {
                                  Severity: Major
                                  Found in core/SanityTests.php and 1 other location - About 4 hrs to fix
                                  core/SanityTests.php on lines 851..866

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

                                  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 2 locations. Consider refactoring.
                                  Open

                                              try {
                                                  $db3 = DBConnection::handle($databaseName3);
                                                  if (\config\ConfAssistant::CONSORTIUM['name'] == "eduroam" && isset(\config\ConfAssistant::CONSORTIUM['deployment-voodoo']) && \config\ConfAssistant::CONSORTIUM['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
                                                      $res3 = $db3->exec('desc view_admin');
                                                      if ($res3->num_rows == $this->viewAdminCount) {
                                  Severity: Major
                                  Found in core/SanityTests.php and 1 other location - About 4 hrs to fix
                                  core/SanityTests.php on lines 833..847

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

                                  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