librenms/librenms

View on GitHub
includes/polling/bgp-peers.inc.php

Summary

Maintainability
D
2 days
Test Coverage

File bgp-peers.inc.php has 706 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

use Illuminate\Support\Str;
use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\RRD\RrdDefinition;
Severity: Major
Found in includes/polling/bgp-peers.inc.php - About 1 day to fix

    Consider simplifying this complex logical expression.
    Open

            if ($device['os_group'] == 'vrp' || $device['os_group'] == 'cisco' || $device['os'] == 'junos' || $device['os'] == 'aos7' || $device['os_group'] === 'arista' || $device['os'] == 'dell-os10' || $device['os'] == 'firebrick') {
                // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB)
                $peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', [$device['device_id'], $peer['bgpPeerIdentifier']]);
                foreach ($peer_afis as $peer_afi) {
                    $afi = $peer_afi['afi'];
    Severity: Major
    Found in includes/polling/bgp-peers.inc.php - About 1 hr to fix

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

                              foreach ($bgpPeersCache as $key => $value) {
                                  $oid = explode('.', $key);
                                  $vrfInstance = $oid[0];
                                  $address = str_replace($oid[0] . '.' . $oid[1] . '.', '', $key);
                                  if (strlen($address) > 15) {
      Severity: Major
      Found in includes/polling/bgp-peers.inc.php and 1 other location - About 2 hrs to fix
      includes/discovery/bgp-peers/timos.inc.php on lines 32..40

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

      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

                          if ($device['os_group'] === 'arista') {
                              $peer_identifier = '1.' . $ip_type . '.' . $ip_len . '.' . $bgp_peer_ident;
                              $mib = 'ARISTA-BGP4V2-MIB';
                              $oid_map = [
                                  'aristaBgp4V2PeerState' => 'bgpPeerState',
      Severity: Major
      Found in includes/polling/bgp-peers.inc.php and 1 other location - About 1 hr to fix
      includes/polling/bgp-peers.inc.php on lines 325..343

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

      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 ($device['os'] == 'dell-os10') {
                              $peer_identifier = '1.' . $ip_type . '.' . $ip_len . '.' . $bgp_peer_ident;
                              $mib = 'DELLEMC-OS10-BGP4V2-MIB';
                              $oid_map = [
                                  'os10bgp4V2PeerState' => 'bgpPeerState',
      Severity: Major
      Found in includes/polling/bgp-peers.inc.php and 1 other location - About 1 hr to fix
      includes/polling/bgp-peers.inc.php on lines 307..407

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

      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

                          if (preg_match('/:/', $peer['bgpPeerIdentifier'])) {
                              $tmp_peer = str_replace(':', '', $peer['bgpPeerIdentifier']);
                              $tmp_peer = preg_replace('/([\w\d]{2})/', '\1:', $tmp_peer);
                              $tmp_peer = rtrim($tmp_peer, ':');
                          } else {
      Severity: Minor
      Found in includes/polling/bgp-peers.inc.php and 1 other location - About 40 mins to fix
      includes/polling/bgp-peers.inc.php on lines 666..672

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

      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

                          if (preg_match('/:/', $peer['bgpPeerIdentifier'])) {
                              $tmp_peer = str_replace(':', '', $peer['bgpPeerIdentifier']);
                              $tmp_peer = preg_replace('/([\w\d]{2})/', '\1:', $tmp_peer);
                              $tmp_peer = rtrim($tmp_peer, ':');
                          } else {
      Severity: Minor
      Found in includes/polling/bgp-peers.inc.php and 1 other location - About 40 mins to fix
      includes/polling/bgp-peers.inc.php on lines 647..653

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

      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

      There are no issues that match your filters.

      Category
      Status