tflori/verja

View on GitHub

Showing 26 of 26 total issues

Function validateTypes has a Cognitive Complexity of 23 (exceeds 9 allowed). Consider refactoring.
Open

    protected function validateTypes(string $number): bool
    {
        foreach ($this->types as $type) {
            // types that we can't validate are valid
            if (!isset(static::$cardTypes[$type])) {
Severity: Minor
Found in src/Validator/CreditCard.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 validate has 60 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function validate($value, array $context = []): bool
    {
        $flags = 0;

        $ipName = 'ip address';
Severity: Major
Found in src/Validator/IpAddress.php - About 2 hrs to fix

    Method validate has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function validate($value, array $context = []): bool
        {
            if (!is_string($value) || !$url = parse_url($value)) {
                // not a string or not a url
                $this->error = new Error(
    Severity: Major
    Found in src/Validator/Url.php - About 2 hrs to fix

      Function validate has a Cognitive Complexity of 21 (exceeds 9 allowed). Consider refactoring.
      Open

          public function validate($value, array $context = []): bool
          {
              if (!is_string($value) || !$url = parse_url($value)) {
                  // not a string or not a url
                  $this->error = new Error(
      Severity: Minor
      Found in src/Validator/Url.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

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

      <?php
      
      namespace Verja\Validator;
      
      use Verja\Error;
      Severity: Major
      Found in src/Validator/Alpha.php and 1 other location - About 2 hrs to fix
      src/Validator/AlphaNumeric.php on lines 1..43

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

      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

      <?php
      
      namespace Verja\Validator;
      
      use Verja\Error;
      Severity: Major
      Found in src/Validator/AlphaNumeric.php and 1 other location - About 2 hrs to fix
      src/Validator/Alpha.php on lines 1..39

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

      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

      Function validate has a Cognitive Complexity of 19 (exceeds 9 allowed). Consider refactoring.
      Open

          public function validate($value, array $context = []): bool
          {
              $flags = 0;
      
              $ipName = 'ip address';
      Severity: Minor
      Found in src/Validator/IpAddress.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 getData has a Cognitive Complexity of 18 (exceeds 9 allowed). Consider refactoring.
      Open

          public function getData(string $key = null, $validate = true)
          {
              if ($key !== null) {
                  if (!isset($this->fields[$key])) {
                      return null;
      Severity: Minor
      Found in src/Gate.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

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

          public function addFilter($filter, $prepend = false)
          {
              $filter = Filter::getFilter($filter);
      
              if (count($this->filterCache) > 0) {
      Severity: Major
      Found in src/Field.php and 1 other location - About 1 hr to fix
      src/Field.php on lines 175..189

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

      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

          public function addValidator($validator, $prepend = false)
          {
              $validator = Validator::getValidator($validator);
      
              if (count($this->validationCache) > 0) {
      Severity: Major
      Found in src/Field.php and 1 other location - About 1 hr to fix
      src/Field.php on lines 104..119

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

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

          public static function assert($field, $value, array $context = [])
          {
              if (!$field instanceof Field) {
                  $definitions = [];
                  if (is_array($field)) {
      Severity: Minor
      Found in src/Gate.php - About 1 hr to fix

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

            public function validate($value, array $context = []): bool
            {
                if (!is_int($value) && !is_double($value)) {
                    $this->error = new Error('NO_NUMBER', $value, 'value should be a number');
                    return false;
        Severity: Minor
        Found in src/Validator/Between.php - About 1 hr to fix

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

              public function getData(string $key = null, $validate = true)
              {
                  if ($key !== null) {
                      if (!isset($this->fields[$key])) {
                          return null;
          Severity: Minor
          Found in src/Gate.php - About 1 hr to fix

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

                public static function create(string $shortName, array $parameters = []): FilterInterface
                {
                    foreach (self::$namespaces as $namespace) {
                        $class = $namespace . '\\' . $shortName;
                        if (!class_exists($class)) {
            Severity: Minor
            Found in src/Filter.php and 1 other location - About 45 mins to fix
            src/Validator.php on lines 124..139

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

            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

                public static function create(string $shortName, array $parameters = []): ValidatorInterface
                {
                    foreach (self::$namespaces as $namespace) {
                        $class = $namespace . '\\' . $shortName;
                        if (!class_exists($class)) {
            Severity: Minor
            Found in src/Validator.php and 1 other location - About 45 mins to fix
            src/Filter.php on lines 105..120

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

            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

                public static function getValidator($validator)
                {
                    if (is_string($validator)) {
                        $validator = static::fromString($validator);
                    } elseif (is_callable($validator) && !$validator instanceof ValidatorInterface) {
            Severity: Minor
            Found in src/Validator.php and 1 other location - About 45 mins to fix
            src/Filter.php on lines 40..53

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

            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

                public function __construct(array $stringTrue = [], array $stringFalse = [], $overwrite = false)
                {
                    if ($overwrite) {
                        $this->stringTrue = $stringTrue;
                        $this->stringFalse = $stringFalse;
            Severity: Minor
            Found in src/Validator/Boolean.php and 1 other location - About 45 mins to fix
            src/Filter/Boolean.php on lines 24..33

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

            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

                public function __construct(array $stringTrue = [], array $stringFalse = [], $overwrite = false)
                {
                    if ($overwrite) {
                        $this->stringTrue = $stringTrue;
                        $this->stringFalse = $stringFalse;
            Severity: Minor
            Found in src/Filter/Boolean.php and 1 other location - About 45 mins to fix
            src/Validator/Boolean.php on lines 23..32

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

            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

                public static function getFilter($filter)
                {
                    if (is_string($filter)) {
                        $filter = Filter::fromString($filter);
                    } elseif (is_callable($filter) && !$filter instanceof FilterInterface) {
            Severity: Minor
            Found in src/Filter.php and 1 other location - About 45 mins to fix
            src/Validator.php on lines 56..69

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

            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

            Avoid too many return statements within this method.
            Open

                                return false;
            Severity: Major
            Found in src/Validator/Url.php - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language