vakata/certificate

View on GitHub

Showing 202 of 202 total issues

File Certificate.php has 884 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace vakata\certificate;

use vakata\asn1\ASN1;
Severity: Major
Found in src/Certificate.php - About 2 days to fix

    Function parseLegacyCertificate has a Cognitive Complexity of 95 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function parseLegacyCertificate(array $cert)
        {
            $iss = null;
            $pro = null;
            $nat = null;
    Severity: Minor
    Found in src/Certificate.php - About 1 day 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

                    if ($pro === '1.5.1.1') {
                        $parsed = $parseSubject(
                            $cert['subject'],
                            [ASN1::TextToOID('stateOrProvinceName'), ASN1::TextToOID('organizationalUnit')],
                            ['EGN'=>'egn', 'PID'=>'pid', 'BULSTAT'=>'bulstat']
    Severity: Major
    Found in src/Certificate.php and 1 other location - About 1 day to fix
    src/Certificate.php on lines 488..522

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

    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

                    } elseif (in_array($pro, ['1.1.1.3', '1.1.1.4', '1.1.1.6'])) {
                        $parsed = $parseSubject(
                            $cert['subject'],
                            [ASN1::TextToOID('organizationalUnit'), ASN1::TextToOID('title')],
                            ['EGN'=>'egn', 'PID'=>'pid', 'B'=>'bulstat']
    Severity: Major
    Found in src/Certificate.php and 1 other location - About 1 day to fix
    src/Certificate.php on lines 353..387

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

    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

    Method parseLegacyCertificate has 282 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function parseLegacyCertificate(array $cert)
        {
            $iss = null;
            $pro = null;
            $nat = null;
    Severity: Major
    Found in src/Certificate.php - About 1 day to fix

      Function isRevokedOCSP has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
      Open

          public function isRevokedOCSP() : bool
          {
              $ocsp = $this->getOCSPPoints();
              if (count($ocsp)) {
                  if ($this->isSelfSigned()) {
      Severity: Minor
      Found in src/Certificate.php - About 1 day 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 verify has a Cognitive Complexity of 63 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function verify(
              string $data,
              string $signature,
              string $publicKey,
              string $algorithm,
      Severity: Minor
      Found in src/Signature.php - About 1 day 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 validatePDF has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function validatePDF(string $pdf) : array
          {
              $signers = [];
              $matches = [];
              $current = -1;
      Severity: Minor
      Found in src/P7S.php - About 6 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

      Certificate has 44 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Certificate
      {
          protected $cert;
          protected $data;
          protected $sign;
      Severity: Minor
      Found in src/Certificate.php - About 6 hrs to fix

        Function parseCertificate has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
        Open

            protected function parseCertificate(string $cert) : array
            {
                try {
                    $orig = Parser::fromString($cert)->toArray();
                    $data = $orig['tbsCertificate'];
        Severity: Minor
        Found in src/Certificate.php - About 4 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 getSubjectData has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
        Open

            public function getSubjectData() : array
            {
                $original = $this->cert['extensions'][ASN1::TextToOID('subjectAltName')] ?? [];
                while (is_array($original) && isset($original[0]) && is_array($original[0]) && isset($original[0][0]) && is_array($original[0][0])) {
                    $original = $original[0];
        Severity: Minor
        Found in src/Certificate.php - About 4 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 verify has 101 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function verify(
                string $data,
                string $signature,
                string $publicKey,
                string $algorithm,
        Severity: Major
        Found in src/Signature.php - About 4 hrs to fix

          The class Certificate has an overall complexity of 231 which is very high. The configured complexity threshold is 50.
          Open

          class Certificate
          {
              protected $cert;
              protected $data;
              protected $sign;
          Severity: Minor
          Found in src/Certificate.php by phpmd

          The class P7S has an overall complexity of 63 which is very high. The configured complexity threshold is 50.
          Open

          class P7S
          {
              protected $p7s;
              protected $raw;
          
          
          Severity: Minor
          Found in src/P7S.php by phpmd

          Method isRevokedOCSP has 78 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function isRevokedOCSP() : bool
              {
                  $ocsp = $this->getOCSPPoints();
                  if (count($ocsp)) {
                      if ($this->isSelfSigned()) {
          Severity: Major
          Found in src/Certificate.php - About 3 hrs to fix

            Function revoked has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

                public function revoked(bool $extensions = false)
                {
                    $temp = $this->data->toArray(false, true)['tbsCertList'];
                    if (isset($temp['revokedCertificates'])) {
                        foreach ($temp['revokedCertificates']->rawData() as $v) {
            Severity: Minor
            Found in src/CRL.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 validateXML has 72 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function validateXML(string $xmlContent, ?Certificate $crt = null) : array
                {
                    $xml = new \DOMDocument();
                    $xml->preserveWhiteSpace = true;
                    $xml->formatOutput = false;
            Severity: Major
            Found in src/P7S.php - About 2 hrs to fix

              Method parseCertificate has 71 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function parseCertificate(string $cert) : array
                  {
                      try {
                          $orig = Parser::fromString($cert)->toArray();
                          $data = $orig['tbsCertificate'];
              Severity: Major
              Found in src/Certificate.php - About 2 hrs to fix

                File P7S.php has 275 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                <?php
                
                namespace vakata\certificate;
                
                use vakata\asn1\ASN1;
                Severity: Minor
                Found in src/P7S.php - About 2 hrs to fix

                  Function getSigners has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getSigners() : array
                      {
                          $signers = [];
                          foreach ($this->p7s->toArray()['data']['signerInfos'] as $k => $v) {
                              $signers[$k] = [
                  Severity: Minor
                  Found in src/P7S.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

                  Severity
                  Category
                  Status
                  Source
                  Language