howardjones/network-weathermap

View on GitHub
lib/Weathermap/Core/HTMLImagemapAreaPolygon.php

Summary

Maintainability
A
45 mins
Test Coverage

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

    public function hitTest($x, $y)
    {
        $c = false;
        // do the easy bounding-box test first.
        if (($x < $this->minx) || ($x > $this->maxx) || ($y < $this->miny) || ($y > $this->maxy)) {
Severity: Minor
Found in lib/Weathermap/Core/HTMLImagemapAreaPolygon.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

Define and throw a dedicated exception instead of using a generic one.
Open

            throw new \Exception('Odd number of points!');

If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

Noncompliant Code Example

throw new Exception();  // Noncompliant

Compliant Solution

throw new InvalidArgumentException();
// or
throw new UnexpectedValueException();

See

There are no issues that match your filters.

Category
Status