phgraph/graph

View on GitHub

Showing 18 of 18 total issues

Function getEdges has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEdges(): array
    {
        if (isset($this->edges)) {
            return $this->edges;
        }
Severity: Minor
Found in src/ShortestPath/MooreBellmanFord.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

Function createScript has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

    public function createScript(): string
    {
        $directed = $this->graph->hasDirected();

        $name = $this->graph->getAttribute('graphviz.name');
Severity: Minor
Found in src/GraphViz/GraphViz.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

Function getEdges has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEdges(): array
    {
        $edge_queue = new SplPriorityQueue();

        /** @var \PHGraph\Edge $edge */
Severity: Minor
Found in src/MinimumSpanningTree/Kruskal.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 getEdges has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEdges(): array
    {
        if (isset($this->edges)) {
            return $this->edges;
        }
Severity: Minor
Found in src/ShortestPath/Dijkstra.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 getEdges has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEdges(): array
    {
        $edges = [];
        $vertex_current = $this->start_vertex;
        $marked = new SplObjectStorage();
Severity: Minor
Found in src/TravelingSalesman/NearestNeighbor.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

Function getEdgesTo has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEdgesTo(Vertex $vertex): array
    {
        if ($vertex === $this->vertex) {
            return [];
        }
Severity: Minor
Found in src/ShortestPath/Dijkstra.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 getEdges has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEdges(): array
    {
        $edge_queue = new SplPriorityQueue();
        $edges = [];

Severity: Minor
Found in src/MinimumSpanningTree/Prim.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 getEdgesTo has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEdgesTo(Vertex $vertex): array
    {
        $current_vertex = $vertex;
        $path = [];

Severity: Minor
Found in src/ShortestPath/MooreBellmanFord.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 newFromVertices has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function newFromVertices(array $vertices): Graph
    {
        $new_graph = new static();
        $new_graph->attributes = $this->attributes;
        $keyed_vertices = [];
Severity: Minor
Found in src/Graph.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

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

    public function addEdgeOut(Edge $edge): void
    {
        if ($edge->isDirected() && $edge->getFrom() !== $this) {
            return;
        }
Severity: Minor
Found in src/Vertex.php and 1 other location - About 40 mins to fix
src/Vertex.php on lines 274..286

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

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 addEdgeIn(Edge $edge): void
    {
        if ($edge->isDirected() && $edge->getTo() !== $this) {
            return;
        }
Severity: Minor
Found in src/Vertex.php and 1 other location - About 40 mins to fix
src/Vertex.php on lines 295..307

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

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

    public function isComplete(): bool
    {
        foreach ($this->vertices as $vertex_a) {
            $connected_vertices = $vertex_a->getVertices();
            foreach ($this->vertices as $vertex_b) {
Severity: Minor
Found in src/Graph.php - About 35 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

Function isBipartit has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function isBipartit(): bool
    {
        if ($this->getNumberOfGroups() !== 2) {
            return false;
        }
Severity: Minor
Found in src/Graph.php - About 35 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

Avoid too many return statements within this method.
Open

                    return $left->getAttribute('weight', 0) - $right->getAttribute('weight', 0);
Severity: Major
Found in src/ShortestPath/MooreBellmanFord.php - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return $this->edges;
    Severity: Major
    Found in src/ShortestPath/MooreBellmanFord.php - About 30 mins to fix

      Function getVertices has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getVertices(): array
          {
              $vertices = [];
              $has_loop = false;
      
      
      Severity: Minor
      Found in src/Vertex.php - About 25 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

      Function removeEdge has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function removeEdge(Edge $edge, bool $disable = false): void
          {
              if (isset($this->edges_in[$edge->getId()])) {
                  if ($disable) {
                      $this->edges_in_disabled[$edge->getId()] = $edge;
      Severity: Minor
      Found in src/Vertex.php - About 25 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

      Function getVertices has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getVertices(): array
          {
              /** @var \PHGraph\Vertex[] $visited */
              $visited = [];
              $queue = new SplQueue();
      Severity: Minor
      Found in src/Search/DepthFirst.php - About 25 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

      Severity
      Category
      Status
      Source
      Language