jkphl/antibot

View on GitHub

Showing 16 of 16 total issues

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

    public function testWhitelistValidator(): void
    {
        $antibot   = new Antibot(md5(rand()));
        $validator = $this->createMock(ValidatorInterface::class);
        $validator->method('validate')->will($this->throwException(new WhitelistValidationException('whitelist')));
Severity: Major
Found in src/Antibot/Tests/Domain/AntibotTest.php and 1 other location - About 5 hrs to fix
src/Antibot/Tests/Domain/AntibotTest.php on lines 135..148

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

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 testBlacklistValidator(): void
    {
        $antibot   = new Antibot(md5(rand()));
        $validator = $this->createMock(ValidatorInterface::class);
        $validator->method('validate')->will($this->throwException(new BlacklistValidationException('blacklist')));
Severity: Major
Found in src/Antibot/Tests/Domain/AntibotTest.php and 1 other location - About 5 hrs to fix
src/Antibot/Tests/Domain/AntibotTest.php on lines 153..166

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

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 testFailingValidator(): void
    {
        $error     = time();
        $antibot   = new Antibot(md5(rand()));
        $validator = $this->createMock(ValidatorInterface::class);
Severity: Major
Found in src/Antibot/Tests/Domain/AntibotTest.php and 1 other location - About 4 hrs to fix
src/Antibot/Tests/Domain/AntibotTest.php on lines 212..225

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

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 testSucceedingValidator(): void
    {
        $error     = time();
        $antibot   = new Antibot(md5(rand()));
        $validator = $this->createMock(ValidatorInterface::class);
Severity: Major
Found in src/Antibot/Tests/Domain/AntibotTest.php and 1 other location - About 4 hrs to fix
src/Antibot/Tests/Domain/AntibotTest.php on lines 194..207

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

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 testIpWhitelist(): void
    {
        $this->expectException(WhitelistValidationException::class);
        $request               = $this->createRequest(['REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '1.2.3.4']);
        $arrayWhitelist1       = new ArrayLookupStrategy(['4.3.2.1']);
Severity: Major
Found in src/Antibot/Tests/Ports/LookupValidatorTest.php and 1 other location - About 2 hrs to fix
src/Antibot/Tests/Ports/LookupValidatorTest.php on lines 74..85

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

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 testIpBlacklist(): void
    {
        $this->expectException(BlacklistValidationException::class);
        $request               = $this->createRequest(['REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '1.2.3.4']);
        $arrayBlacklist1       = new ArrayLookupStrategy(['4.3.2.1']);
Severity: Major
Found in src/Antibot/Tests/Ports/LookupValidatorTest.php and 1 other location - About 2 hrs to fix
src/Antibot/Tests/Ports/LookupValidatorTest.php on lines 58..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 140.

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 validateRequest has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function validateRequest(
        ServerRequestInterface $request,
        ValidationResultInterface $result
    ): ValidationResultInterface {
        $this->logger->info('Start validation');
Severity: Minor
Found in src/Antibot/Domain/Antibot.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 validateRequestTiming has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    protected function validateRequestTiming(string $hmac, Antibot $antibot, array $hmacParams): bool
    {
        // If submission time checks are enabled
        if (!empty($this->submissionTimes)) {
            list($first, $min, $max) = $this->submissionTimes;
Severity: Minor
Found in src/Antibot/Ports/Validators/HmacValidator.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 testRequestTimingValidation has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function testRequestTimingValidation(): void
    {
        $session       = md5(rand());
        $antibot       = $this->createAntibot($session);
        $hmacValidator = new HmacValidator();
Severity: Minor
Found in src/Antibot/Tests/Ports/HmacValidatorTest.php - About 1 hr to fix

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

        protected function validateHoneypotsRecursive(array $honeypots, array $data, Antibot $antibot, $prefix = null): bool
        {
            // Run through the honeypot configuration
            foreach ($honeypots as $name => $config) {
                if (is_array($config)) {
    Severity: Minor
    Found in src/Antibot/Ports/Validators/HoneypotValidator.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 testHoneypots has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function testHoneypots(): void
        {
            $renderer          = function (InputElement $input, string $html) {
                return '<label style="display:none">' . $html . '</label>';
            };
    Severity: Minor
    Found in src/Antibot/Tests/Ports/HoneypotValidatorTest.php - About 1 hr to fix

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

          protected function validateRequestTiming(string $hmac, Antibot $antibot, array $hmacParams): bool
          {
              // If submission time checks are enabled
              if (!empty($this->submissionTimes)) {
                  list($first, $min, $max) = $this->submissionTimes;
      Severity: Minor
      Found in src/Antibot/Ports/Validators/HmacValidator.php - About 1 hr to fix

        Method probeTimedHmac has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                string $hmac,
                Antibot $antibot,
                array $hmacParams,
                int $timestamp,
                bool $followUp = false
        Severity: Minor
        Found in src/Antibot/Ports/Validators/HmacValidator.php - About 35 mins to fix

          Method probeTimedHmacAsInitialAndFollowup has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  string $hmac,
                  Antibot $antibot,
                  array $hmacParams,
                  int $timestamp,
                  int $initial
          Severity: Minor
          Found in src/Antibot/Ports/Validators/HmacValidator.php - About 35 mins to fix

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

            <?php
            
            /**
             * antibot
             *
            Severity: Minor
            Found in src/Antibot/Ports/Validators/IpWhitelistValidator.php and 1 other location - About 30 mins to fix
            src/Antibot/Ports/Validators/IpBlacklistValidator.php on lines 1..85

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

            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
            
            /**
             * antibot
             *
            Severity: Minor
            Found in src/Antibot/Ports/Validators/IpBlacklistValidator.php and 1 other location - About 30 mins to fix
            src/Antibot/Ports/Validators/IpWhitelistValidator.php on lines 1..85

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

            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

            Severity
            Category
            Status
            Source
            Language