njuhel/php-swagger-to-md

View on GitHub

Showing 181 of 181 total issues

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

    protected function getResourceForKey($key)
    {
        $resources = explode('/', trim($key, '/'));

        if (count($resources) < 2) {
Severity: Major
Found in src/SwaggerValidator/Object/PathItem.php and 1 other location - About 2 hrs to fix
src/SwaggerValidator/Object/Paths.php on lines 143..161

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

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

Swagger2md has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

class Swagger2md
{

    const version = '1.0.0';

Severity: Minor
Found in src/Swagger2md.php - About 2 hrs to fix

    Method markdown has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function markdown(\SwaggerValidator\Common\Context $context)
        {
            $method               = __FUNCTION__;
            $schemaKey            = \SwaggerValidator\Common\FactorySwagger::KEY_SCHEMA;
            $templateVars         = array();
    Severity: Major
    Found in src/SwaggerValidator/Object/ParameterBody.php - About 2 hrs to fix

      Method markdown has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function markdown(\SwaggerValidator\Common\Context $context, $generalItems)
          {
              $method         = __FUNCTION__;
              $generalItems   = $this->getMethodGeneric($context, $method, $generalItems);
              $exampleRequest = $this->makeRequestExample($context, $generalItems);
      Severity: Major
      Found in src/SwaggerValidator/Object/Operation.php - About 2 hrs to fix

        Method markdown has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function markdown(\SwaggerValidator\Common\Context $context)
            {
                $method       = __FUNCTION__;
                $templateVars = array(
                    'items' => array(),
        Severity: Major
        Found in src/SwaggerValidator/DataType/TypeArrayItems.php - About 2 hrs to fix

          Method markdown has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function markdown(\SwaggerValidator\Common\Context $context)
              {
                  $method       = __FUNCTION__;
                  $keyTags      = \SwaggerValidator\Common\FactorySwagger::KEY_TAGS;
                  $generalItems = $this->getMethodGeneric($context, $method);
          Severity: Minor
          Found in src/SwaggerValidator/Object/Swagger.php - About 2 hrs to fix

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

                public function markdown(\SwaggerValidator\Common\Context $context, $generalItems)
                {
                    $method = __FUNCTION__;
                    $context->setType(\SwaggerValidator\Common\Context::TYPE_REQUEST);
            
            
            Severity: Minor
            Found in src/SwaggerValidator/Object/Parameters.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 getTags has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getTags(\SwaggerValidator\Common\Context $context, $tags)
                {
                    $method  = __FUNCTION__;
                    $keyTags = \SwaggerValidator\Common\FactorySwagger::KEY_TAGS;
                    $curPath = $context->getRoutePath();
            Severity: Minor
            Found in src/SwaggerValidator/Object/PathItem.php - About 1 hr to fix

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

                  public function markdown(\SwaggerValidator\Common\Context $context, $generalItems)
                  {
                      $method         = __FUNCTION__;
                      $generalItems   = $this->getMethodGeneric($context, $method, $generalItems);
                      $exampleRequest = $this->makeRequestExample($context, $generalItems);
              Severity: Minor
              Found in src/SwaggerValidator/Object/Operation.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

              Avoid using undefined variables such as '$paths' which will lead to PHP notices.
              Open

                              $templateVars[$key] = $this->$key->$method($context->setDataPath($paths), $generalItems);

              UndefinedVariable

              Since: 2.8.0

              Detects when a variable is used that has not been defined before.

              Example

              class Foo
              {
                  private function bar()
                  {
                      // $message is undefined
                      echo $message;
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#undefinedvariable

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

                  public function markdown(\SwaggerValidator\Common\Context $context, $generalItems)
                  {
                      $method       = __FUNCTION__;
                      $generalItems = $this->getMethodGeneric($context, $method, $generalItems);
                      $tplResources = array();
              Severity: Minor
              Found in src/SwaggerValidator/Object/Paths.php - About 1 hr to fix

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

                    final public static function autoload($className)
                    {
                        if (\Phar::running() && defined('PHAR_SWG2MD_ROOT_PATH')) {
                            $baseDir = PHAR_SWG2MD_ROOT_PATH;
                        }
                Severity: Minor
                Found in src/Swagger2mdAutoload.php - About 1 hr to fix

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

                      public function getSummary(\SwaggerValidator\Common\Context $context)
                      {
                          $method = __FUNCTION__;
                  
                          $summary  = array();
                  Severity: Minor
                  Found in src/SwaggerValidator/Object/Paths.php - About 1 hr to fix

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

                        public function markdown(\SwaggerValidator\Common\Context $context, $generalItems)
                        {
                            $method = __FUNCTION__;
                            $context->setType(\SwaggerValidator\Common\Context::TYPE_REQUEST);
                    
                    
                    Severity: Minor
                    Found in src/SwaggerValidator/Object/Parameters.php - About 1 hr to fix

                      Method markdown has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function markdown(\SwaggerValidator\Common\Context $context, $generalItems)
                          {
                              $method       = __FUNCTION__;
                              $generalItems = $this->getMethodGeneric($context, $method, $generalItems);
                              $tplOperation = array();
                      Severity: Minor
                      Found in src/SwaggerValidator/Object/PathItem.php - About 1 hr to fix

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

                            final public static function autoload($className)
                            {
                                if (\Phar::running() && defined('PHAR_SWG2MD_ROOT_PATH')) {
                                    $baseDir = PHAR_SWG2MD_ROOT_PATH;
                                }
                        Severity: Minor
                        Found in src/Swagger2mdAutoload.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

                        Method renderTable has 7 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            public function renderTable($name, $anchor, $listKey, $colonsFile, $template, $vars, $store = null)
                        Severity: Major
                        Found in src/Swagger2md.php - About 50 mins to fix

                          Avoid variables with short names like $in. Configured minimum length is 3.
                          Open

                                      $in    = null;

                          ShortVariable

                          Since: 0.2

                          Detects when a field, local, or parameter has a very short name.

                          Example

                          class Something {
                              private $q = 15; // VIOLATION - Field
                              public static function main( array $as ) { // VIOLATION - Formal
                                  $r = 20 + $this->q; // VIOLATION - Local
                                  for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                      $r += $this->q;
                                  }
                              }
                          }

                          Source https://phpmd.org/rules/naming.html#shortvariable

                          Function apache_request_headers has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                              function apache_request_headers()
                              {
                                  $arh = array();
                          
                                  foreach ($_SERVER as $key => $val) {
                          Severity: Minor
                          Found in src/Compat.php - About 45 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

                          The class Override has a coupling between objects value of 27. Consider to reduce the number of dependencies under 13.
                          Open

                          class Override
                          {
                          
                              public static function override()
                              {
                          Severity: Minor
                          Found in src/SwaggerValidator/Override.php by phpmd

                          CouplingBetweenObjects

                          Since: 1.1.0

                          A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                          Example

                          class Foo {
                              /**
                               * @var \foo\bar\X
                               */
                              private $x = null;
                          
                              /**
                               * @var \foo\bar\Y
                               */
                              private $y = null;
                          
                              /**
                               * @var \foo\bar\Z
                               */
                              private $z = null;
                          
                              public function setFoo(\Foo $foo) {}
                              public function setBar(\Bar $bar) {}
                              public function setBaz(\Baz $baz) {}
                          
                              /**
                               * @return \SplObjectStorage
                               * @throws \OutOfRangeException
                               * @throws \InvalidArgumentException
                               * @throws \ErrorException
                               */
                              public function process(\Iterator $it) {}
                          
                              // ...
                          }

                          Source https://phpmd.org/rules/design.html#couplingbetweenobjects

                          Severity
                          Category
                          Status
                          Source
                          Language