librenms/librenms

View on GitHub
includes/html/api_functions.inc.php

Summary

Maintainability
F
1 mo
Test Coverage

File api_functions.inc.php has 2667 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/*
 * LibreNMS
 *
Severity: Major
Found in includes/html/api_functions.inc.php - About 1 wk to fix

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

    function create_edit_bill(Illuminate\Http\Request $request)
    {
        $data = json_decode($request->getContent(), true);
        if (! $data) {
            return api_error(500, 'Invalid JSON data');
    Severity: Minor
    Found in includes/html/api_functions.inc.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 list_oxidized has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

    function list_oxidized(Illuminate\Http\Request $request)
    {
        $return = [];
        $devices = Device::query()
                ->with('attribs')
    Severity: Minor
    Found in includes/html/api_functions.inc.php - About 5 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 add_edit_rule has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    function add_edit_rule(Illuminate\Http\Request $request)
    {
        $data = json_decode($request->getContent(), true);
        if (json_last_error() || ! is_array($data)) {
            return api_error(500, "We couldn't parse the provided json");
    Severity: Minor
    Found in includes/html/api_functions.inc.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

    Method create_edit_bill has 109 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function create_edit_bill(Illuminate\Http\Request $request)
    {
        $data = json_decode($request->getContent(), true);
        if (! $data) {
            return api_error(500, 'Invalid JSON data');
    Severity: Major
    Found in includes/html/api_functions.inc.php - About 4 hrs to fix

      Function list_devices has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

      function list_devices(Illuminate\Http\Request $request)
      {
          // This will return a list of devices
      
          $order = $request->get('order');
      Severity: Minor
      Found in includes/html/api_functions.inc.php - About 3 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 update_device has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

      function update_device(Illuminate\Http\Request $request)
      {
          $hostname = $request->route('hostname');
          // use hostname as device_id if it's all digits
          $device = ctype_digit($hostname) ? Device::find($hostname) : Device::findByHostname($hostname);
      Severity: Minor
      Found in includes/html/api_functions.inc.php - About 3 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 add_edit_rule has 93 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function add_edit_rule(Illuminate\Http\Request $request)
      {
          $data = json_decode($request->getContent(), true);
          if (json_last_error() || ! is_array($data)) {
              return api_error(500, "We couldn't parse the provided json");
      Severity: Major
      Found in includes/html/api_functions.inc.php - About 3 hrs to fix

        Method list_devices has 81 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function list_devices(Illuminate\Http\Request $request)
        {
            // This will return a list of devices
        
            $order = $request->get('order');
        Severity: Major
        Found in includes/html/api_functions.inc.php - About 3 hrs to fix

          Method list_bills has 75 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function list_bills(Illuminate\Http\Request $request)
          {
              $bills = [];
              $bill_id = $request->route('bill_id');
              $bill_ref = $request->get('ref');
          Severity: Major
          Found in includes/html/api_functions.inc.php - About 3 hrs to fix

            Method list_logs has 65 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function list_logs(Illuminate\Http\Request $request, Router $router)
            {
                $type = $router->current()->getName();
                $hostname = $request->route('hostname');
                $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
            Severity: Major
            Found in includes/html/api_functions.inc.php - About 2 hrs to fix

              Method list_bgp has 65 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function list_bgp(Illuminate\Http\Request $request)
              {
                  $sql = '';
                  $sql_params = [];
                  $hostname = $request->get('hostname');
              Severity: Major
              Found in includes/html/api_functions.inc.php - About 2 hrs to fix

                Function list_bills has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                Open

                function list_bills(Illuminate\Http\Request $request)
                {
                    $bills = [];
                    $bill_id = $request->route('bill_id');
                    $bill_ref = $request->get('ref');
                Severity: Minor
                Found in includes/html/api_functions.inc.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 list_oxidized has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function list_oxidized(Illuminate\Http\Request $request)
                {
                    $return = [];
                    $devices = Device::query()
                            ->with('attribs')
                Severity: Major
                Found in includes/html/api_functions.inc.php - About 2 hrs to fix

                  Function list_bgp has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function list_bgp(Illuminate\Http\Request $request)
                  {
                      $sql = '';
                      $sql_params = [];
                      $hostname = $request->get('hostname');
                  Severity: Minor
                  Found in includes/html/api_functions.inc.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 list_logs has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function list_logs(Illuminate\Http\Request $request, Router $router)
                  {
                      $type = $router->current()->getName();
                      $hostname = $request->route('hostname');
                      $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                  Severity: Minor
                  Found in includes/html/api_functions.inc.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 list_available_health_graphs has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function list_available_health_graphs(Illuminate\Http\Request $request)
                  {
                      $hostname = $request->route('hostname');
                      $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                  
                  
                  Severity: Major
                  Found in includes/html/api_functions.inc.php - About 2 hrs to fix

                    Method add_device has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function add_device(Illuminate\Http\Request $request)
                    {
                        // This will add a device using the data passed encoded with json
                        $data = $request->json()->all();
                    
                    
                    Severity: Minor
                    Found in includes/html/api_functions.inc.php - About 1 hr to fix

                      Method update_device_group has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function update_device_group(Illuminate\Http\Request $request)
                      {
                          $data = json_decode($request->getContent(), true);
                          if (json_last_error() || ! is_array($data)) {
                              return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                      Severity: Minor
                      Found in includes/html/api_functions.inc.php - About 1 hr to fix

                        Method update_device has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        function update_device(Illuminate\Http\Request $request)
                        {
                            $hostname = $request->route('hostname');
                            // use hostname as device_id if it's all digits
                            $device = ctype_digit($hostname) ? Device::find($hostname) : Device::findByHostname($hostname);
                        Severity: Minor
                        Found in includes/html/api_functions.inc.php - About 1 hr to fix

                          Method list_alerts has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function list_alerts(Illuminate\Http\Request $request): JsonResponse
                          {
                              $id = $request->route('id');
                          
                              $sql = 'SELECT `D`.`hostname`, `A`.*, `R`.`severity` FROM `alerts` AS `A`, `devices` AS `D`, `alert_rules` AS `R` WHERE `D`.`device_id` = `A`.`device_id` AND `A`.`rule_id` = `R`.`id` ';
                          Severity: Minor
                          Found in includes/html/api_functions.inc.php - About 1 hr to fix

                            Method maintenance_device has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function maintenance_device(Illuminate\Http\Request $request)
                            {
                                if (empty($request->json())) {
                                    return api_error(400, 'No information has been provided to set this device into maintenance');
                                }
                            Severity: Minor
                            Found in includes/html/api_functions.inc.php - About 1 hr to fix

                              Method maintenance_devicegroup has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              function maintenance_devicegroup(Illuminate\Http\Request $request)
                              {
                                  if (empty($request->json())) {
                                      return api_error(400, 'No information has been provided to set this device into maintenance');
                                  }
                              Severity: Minor
                              Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                Function list_alerts has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                                Open

                                function list_alerts(Illuminate\Http\Request $request): JsonResponse
                                {
                                    $id = $request->route('id');
                                
                                    $sql = 'SELECT `D`.`hostname`, `A`.*, `R`.`severity` FROM `alerts` AS `A`, `devices` AS `D`, `alert_rules` AS `R` WHERE `D`.`device_id` = `A`.`device_id` AND `A`.`rule_id` = `R`.`id` ';
                                Severity: Minor
                                Found in includes/html/api_functions.inc.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 update_device_group has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                                Open

                                function update_device_group(Illuminate\Http\Request $request)
                                {
                                    $data = json_decode($request->getContent(), true);
                                    if (json_last_error() || ! is_array($data)) {
                                        return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                Severity: Minor
                                Found in includes/html/api_functions.inc.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 get_port_stats_by_port_hostname has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                function get_port_stats_by_port_hostname(Illuminate\Http\Request $request)
                                {
                                    $ifName = $request->route('ifname');
                                
                                    // handle %2f in paths and pass to get_graph_by_port_hostname if needed
                                Severity: Minor
                                Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                  Method api_get_graph has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  function api_get_graph(Request $request, array $additional = [])
                                  {
                                      try {
                                          $vars = $request->only([
                                              'from',
                                  Severity: Minor
                                  Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                    Method list_services has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                    function list_services(Illuminate\Http\Request $request)
                                    {
                                        $where = [];
                                        $params = [];
                                    
                                    
                                    Severity: Minor
                                    Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                      Method add_device_group has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                      function add_device_group(Illuminate\Http\Request $request)
                                      {
                                          $data = json_decode($request->getContent(), true);
                                          if (json_last_error() || ! is_array($data)) {
                                              return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                      Severity: Minor
                                      Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                        Method list_available_wireless_graphs has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                        function list_available_wireless_graphs(Illuminate\Http\Request $request)
                                        {
                                            $hostname = $request->route('hostname');
                                            $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                        
                                        
                                        Severity: Minor
                                        Found in includes/html/api_functions.inc.php - About 1 hr to fix

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

                                          function list_arp(Illuminate\Http\Request $request)
                                          {
                                              $query = $request->route('query');
                                              $cidr = $request->route('cidr');
                                              $hostname = $request->get('device');
                                          Severity: Minor
                                          Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                            Function check_bill_key_value has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                            function check_bill_key_value($bill_key, $bill_value)
                                            {
                                                $bill_types = ['quota', 'cdr'];
                                            
                                                switch ($bill_key) {
                                            Severity: Minor
                                            Found in includes/html/api_functions.inc.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 update_port_description has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                            Open

                                            function update_port_description(Illuminate\Http\Request $request)
                                            {
                                                $port_id = $request->route('portid');
                                                $port = Port::hasAccess(Auth::user())
                                                    ->where([
                                            Severity: Minor
                                            Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                              Method list_vrf has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                              Open

                                              function list_vrf(Illuminate\Http\Request $request)
                                              {
                                                  $sql = '';
                                                  $sql_params = [];
                                                  $hostname = $request->get('hostname');
                                              Severity: Minor
                                              Found in includes/html/api_functions.inc.php - About 1 hr to fix

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

                                                function add_service_template_for_device_group(Illuminate\Http\Request $request)
                                                {
                                                    $data = json_decode($request->getContent(), true);
                                                    if (json_last_error() || ! is_array($data)) {
                                                        return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                Severity: Minor
                                                Found in includes/html/api_functions.inc.php - About 1 hr to fix

                                                  Function list_arp has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                  function list_arp(Illuminate\Http\Request $request)
                                                  {
                                                      $query = $request->route('query');
                                                      $cidr = $request->route('cidr');
                                                      $hostname = $request->get('device');
                                                  Severity: Minor
                                                  Found in includes/html/api_functions.inc.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

                                                  Function del_parents_from_host has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                                  Open

                                                  function del_parents_from_host(Illuminate\Http\Request $request)
                                                  {
                                                      $device_id = $request->route('id');
                                                      $device_id = ctype_digit($device_id) ? $device_id : getidbyname($device_id);
                                                      $data = json_decode($request->getContent(), true);
                                                  Severity: Minor
                                                  Found in includes/html/api_functions.inc.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

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

                                                  function api_success($result, $result_name, $message = null, $code = 200, $count = null, $extra = null): JsonResponse
                                                  {
                                                      if (isset($result) && ! isset($result_name)) {
                                                          return api_error(500, 'Result name not specified');
                                                      }
                                                  Severity: Minor
                                                  Found in includes/html/api_functions.inc.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

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

                                                  function add_device_group(Illuminate\Http\Request $request)
                                                  {
                                                      $data = json_decode($request->getContent(), true);
                                                      if (json_last_error() || ! is_array($data)) {
                                                          return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                  Severity: Minor
                                                  Found in includes/html/api_functions.inc.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

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

                                                  function maintenance_device(Illuminate\Http\Request $request)
                                                  {
                                                      if (empty($request->json())) {
                                                          return api_error(400, 'No information has been provided to set this device into maintenance');
                                                      }
                                                  Severity: Minor
                                                  Found in includes/html/api_functions.inc.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

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

                                                  function list_services(Illuminate\Http\Request $request)
                                                  {
                                                      $where = [];
                                                      $params = [];
                                                  
                                                  
                                                  Severity: Minor
                                                  Found in includes/html/api_functions.inc.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

                                                  Method api_success has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                                  Open

                                                  function api_success($result, $result_name, $message = null, $code = 200, $count = null, $extra = null): JsonResponse
                                                  Severity: Minor
                                                  Found in includes/html/api_functions.inc.php - About 45 mins to fix

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

                                                    function maintenance_devicegroup(Illuminate\Http\Request $request)
                                                    {
                                                        if (empty($request->json())) {
                                                            return api_error(400, 'No information has been provided to set this device into maintenance');
                                                        }
                                                    Severity: Minor
                                                    Found in includes/html/api_functions.inc.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 api_error(500, 'Failed to update existing bgp');
                                                    Severity: Major
                                                    Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return api_error(500, "We couldn't parse your rule");
                                                      Severity: Major
                                                      Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                    return api_error(500, 'Argument bill_id is not allowed on bill create (auto assigned)');
                                                        Severity: Major
                                                        Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                      return api_error(500, 'Missing parameters: ' . $missing_keys);
                                                          Severity: Major
                                                          Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                    return api_success_noresult(201, "Device {$device->hostname} ({$device->device_id}) moved into maintenance mode" . ($duration ? " for {$duration}h" : ''));
                                                            Severity: Major
                                                            Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                          return api_error(500, 'Failed to create new bill');
                                                              Severity: Major
                                                              Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                            return api_error(500, 'Addition failed : Name has already been used');
                                                                Severity: Major
                                                                Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                          return api_error(500, 'Update failed : Invalid rule id');
                                                                  Severity: Major
                                                                  Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                        return true;
                                                                    Severity: Major
                                                                    Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                              return api_error(400, 'Missing the severity');
                                                                      Severity: Major
                                                                      Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                        Avoid too many return statements within this method.
                                                                        Open

                                                                            return api_success_noresult(200);
                                                                        Severity: Major
                                                                        Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                          Avoid too many return statements within this method.
                                                                          Open

                                                                                          return $res;
                                                                          Severity: Major
                                                                          Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                            Avoid too many return statements within this method.
                                                                            Open

                                                                                        return api_error(500, 'Failed to update existing alert rule');
                                                                            Severity: Major
                                                                            Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                              Avoid too many return statements within this method.
                                                                              Open

                                                                                      return api_error(500, 'Failed to create new alert rule');
                                                                              Severity: Major
                                                                              Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                Avoid too many return statements within this method.
                                                                                Open

                                                                                        return api_error(500, 'Device ' . $data['field'] . ' field failed to be updated');
                                                                                Severity: Major
                                                                                Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                  Avoid too many return statements within this method.
                                                                                  Open

                                                                                          return api_success_noresult(201, "Device group {$device_group->name} ({$device_group->id}) will begin maintenance mode at $start" . ($duration ? " for {$duration}h" : ''));
                                                                                  Severity: Major
                                                                                  Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                    Avoid too many return statements within this method.
                                                                                    Open

                                                                                            return api_success_noresult(201, "Device group {$device_group->name} ({$device_group->id}) moved into maintenance mode" . ($duration ? " for {$duration}h" : ''));
                                                                                    Severity: Major
                                                                                    Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                      Avoid too many return statements within this method.
                                                                                      Open

                                                                                                      return api_success_noresult(200, 'Device fields have been updated');
                                                                                      Severity: Major
                                                                                      Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                        Avoid too many return statements within this method.
                                                                                        Open

                                                                                                        return api_error(500, 'Device fields failed to be updated');
                                                                                        Severity: Major
                                                                                        Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                          Avoid too many return statements within this method.
                                                                                          Open

                                                                                                  return api_error(422, $v->messages());
                                                                                          Severity: Major
                                                                                          Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                            Avoid too many return statements within this method.
                                                                                            Open

                                                                                                    return api_error(422, $v->messages());
                                                                                            Severity: Major
                                                                                            Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                              Avoid too many return statements within this method.
                                                                                              Open

                                                                                                      return api_success_noresult(200, 'Device ' . $data['field'] . ' field has been updated');
                                                                                              Severity: Major
                                                                                              Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                                Avoid too many return statements within this method.
                                                                                                Open

                                                                                                        return api_error(500, 'Failed to save changes device group');
                                                                                                Severity: Major
                                                                                                Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                                  Avoid too many return statements within this method.
                                                                                                  Open

                                                                                                              return api_error(500, "We couldn't parse your rule");
                                                                                                  Severity: Major
                                                                                                  Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                                    Avoid too many return statements within this method.
                                                                                                    Open

                                                                                                                return api_error(500, 'Device fields failed to be updated as the number of fields (' . count($data['field']) . ') does not match the supplied data (' . count($data['data']) . ')');
                                                                                                    Severity: Major
                                                                                                    Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                                      Avoid too many return statements within this method.
                                                                                                      Open

                                                                                                          return api_success($bill_id, 'bill_id');
                                                                                                      Severity: Major
                                                                                                      Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                                        Avoid too many return statements within this method.
                                                                                                        Open

                                                                                                            return api_success_noresult(200, "Device group $name updated");
                                                                                                        Severity: Major
                                                                                                        Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                                          Avoid too many return statements within this method.
                                                                                                          Open

                                                                                                              return api_success_noresult(200, 'Devices removed');
                                                                                                          Severity: Major
                                                                                                          Found in includes/html/api_functions.inc.php - About 30 mins to fix

                                                                                                            Avoid too many return statements within this method.
                                                                                                            Open

                                                                                                                return api_success_noresult(200, 'Devices added');
                                                                                                            Severity: Major
                                                                                                            Found in includes/html/api_functions.inc.php - About 30 mins to fix

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

                                                                                                              function add_device(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  // This will add a device using the data passed encoded with json
                                                                                                                  $data = $request->json()->all();
                                                                                                              
                                                                                                              
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.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 update_device_group_add_devices has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                              Open

                                                                                                              function update_device_group_add_devices(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.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 list_vrf has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                              Open

                                                                                                              function list_vrf(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $sql = '';
                                                                                                                  $sql_params = [];
                                                                                                                  $hostname = $request->get('hostname');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.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 get_port_stats_by_port_hostname has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                              Open

                                                                                                              function get_port_stats_by_port_hostname(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $ifName = $request->route('ifname');
                                                                                                              
                                                                                                                  // handle %2f in paths and pass to get_graph_by_port_hostname if needed
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.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 rename_device has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                              Open

                                                                                                              function rename_device(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                                  $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                                  $new_hostname = $request->route('new_hostname');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.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 update_device_group_remove_devices has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                                                                              Open

                                                                                                              function update_device_group_remove_devices(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.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

                                                                                                              The function add_service_for_host() has an NPath complexity of 256. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function add_service_for_host(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                                  $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function maintenance_device() has an NPath complexity of 512. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function maintenance_device(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  if (empty($request->json())) {
                                                                                                                      return api_error(400, 'No information has been provided to set this device into maintenance');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function list_oxidized() has an NPath complexity of 1393. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function list_oxidized(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $return = [];
                                                                                                                  $devices = Device::query()
                                                                                                                          ->with('attribs')
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function create_edit_bill() has 129 lines of code. Current threshold is set to 100. Avoid really long methods.
                                                                                                              Open

                                                                                                              function create_edit_bill(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (! $data) {
                                                                                                                      return api_error(500, 'Invalid JSON data');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              The function add_edit_rule() has 110 lines of code. Current threshold is set to 100. Avoid really long methods.
                                                                                                              Open

                                                                                                              function add_edit_rule(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(500, "We couldn't parse the provided json");
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              The function list_devices() has an NPath complexity of 684. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function list_devices(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  // This will return a list of devices
                                                                                                              
                                                                                                                  $order = $request->get('order');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function update_device() has an NPath complexity of 288. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function update_device(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                                  // use hostname as device_id if it's all digits
                                                                                                                  $device = ctype_digit($hostname) ? Device::find($hostname) : Device::findByHostname($hostname);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function maintenance_devicegroup() has an NPath complexity of 256. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function maintenance_devicegroup(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  if (empty($request->json())) {
                                                                                                                      return api_error(400, 'No information has been provided to set this device into maintenance');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function update_device_group() has an NPath complexity of 2592. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function update_device_group(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function api_success() has an NPath complexity of 216. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function api_success($result, $result_name, $message = null, $code = 200, $count = null, $extra = null): JsonResponse
                                                                                                              {
                                                                                                                  if (isset($result) && ! isset($result_name)) {
                                                                                                                      return api_error(500, 'Result name not specified');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function list_bgp() has an NPath complexity of 9216. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function list_bgp(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $sql = '';
                                                                                                                  $sql_params = [];
                                                                                                                  $hostname = $request->get('hostname');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function add_edit_rule() has an NPath complexity of 435456. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function add_edit_rule(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(500, "We couldn't parse the provided json");
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function create_edit_bill() has an NPath complexity of 6160. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function create_edit_bill(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (! $data) {
                                                                                                                      return api_error(500, 'Invalid JSON data');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function list_logs() has an NPath complexity of 1080. The configured NPath complexity threshold is 200.
                                                                                                              Open

                                                                                                              function list_logs(Illuminate\Http\Request $request, Router $router)
                                                                                                              {
                                                                                                                  $type = $router->current()->getName();
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                                  $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              NPathComplexity

                                                                                                              Since: 0.1

                                                                                                              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  function bar() {
                                                                                                                      // lots of complicated code
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#npathcomplexity

                                                                                                              The function check_bill_key_value() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function check_bill_key_value($bill_key, $bill_value)
                                                                                                              {
                                                                                                                  $bill_types = ['quota', 'cdr'];
                                                                                                              
                                                                                                                  switch ($bill_key) {
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function list_bgp() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function list_bgp(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $sql = '';
                                                                                                                  $sql_params = [];
                                                                                                                  $hostname = $request->get('hostname');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function maintenance_devicegroup() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function maintenance_devicegroup(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  if (empty($request->json())) {
                                                                                                                      return api_error(400, 'No information has been provided to set this device into maintenance');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function list_bills() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function list_bills(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $bills = [];
                                                                                                                  $bill_id = $request->route('bill_id');
                                                                                                                  $bill_ref = $request->get('ref');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function api_success() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function api_success($result, $result_name, $message = null, $code = 200, $count = null, $extra = null): JsonResponse
                                                                                                              {
                                                                                                                  if (isset($result) && ! isset($result_name)) {
                                                                                                                      return api_error(500, 'Result name not specified');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function create_edit_bill() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function create_edit_bill(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (! $data) {
                                                                                                                      return api_error(500, 'Invalid JSON data');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function update_device() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function update_device(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                                  // use hostname as device_id if it's all digits
                                                                                                                  $device = ctype_digit($hostname) ? Device::find($hostname) : Device::findByHostname($hostname);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function update_device_group() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function update_device_group(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function list_oxidized() has a Cyclomatic Complexity of 18. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function list_oxidized(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $return = [];
                                                                                                                  $devices = Device::query()
                                                                                                                          ->with('attribs')
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function list_devices() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function list_devices(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  // This will return a list of devices
                                                                                                              
                                                                                                                  $order = $request->get('order');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function maintenance_device() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function maintenance_device(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  if (empty($request->json())) {
                                                                                                                      return api_error(400, 'No information has been provided to set this device into maintenance');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function list_logs() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function list_logs(Illuminate\Http\Request $request, Router $router)
                                                                                                              {
                                                                                                                  $type = $router->current()->getName();
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                                  $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function del_parents_from_host() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function del_parents_from_host(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $device_id = $request->route('id');
                                                                                                                  $device_id = ctype_digit($device_id) ? $device_id : getidbyname($device_id);
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function add_edit_rule() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function add_edit_rule(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(500, "We couldn't parse the provided json");
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              The function list_available_health_graphs() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10.
                                                                                                              Open

                                                                                                              function list_available_health_graphs(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                                  $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                              
                                                                                                              
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              CyclomaticComplexity

                                                                                                              Since: 0.1

                                                                                                              Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                                                              Example

                                                                                                              // Cyclomatic Complexity = 11
                                                                                                              class Foo {
                                                                                                              1   public function example() {
                                                                                                              2       if ($a == $b) {
                                                                                                              3           if ($a1 == $b1) {
                                                                                                                              fiddle();
                                                                                                              4           } elseif ($a2 == $b2) {
                                                                                                                              fiddle();
                                                                                                                          } else {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              5       } elseif ($c == $d) {
                                                                                                              6           while ($c == $d) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                              7        } elseif ($e == $f) {
                                                                                                              8           for ($n = 0; $n < $h; $n++) {
                                                                                                                              fiddle();
                                                                                                                          }
                                                                                                                      } else {
                                                                                                                          switch ($z) {
                                                                                                              9               case 1:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              10              case 2:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                              11              case 3:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                              default:
                                                                                                                                  fiddle();
                                                                                                                                  break;
                                                                                                                          }
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

                                                                                                              Avoid using undefined variables such as '$parent_ids' which will lead to PHP notices.
                                                                                                              Open

                                                                                                                      $result = validateDeviceIds($parent_ids) ? $device->parents()->detach($parent_ids) : false;
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              UndefinedVariable

                                                                                                              Since: 2.8.0

                                                                                                              Detects when a variable is used that has not been defined before.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  private function bar()
                                                                                                                  {
                                                                                                                      // $message is undefined
                                                                                                                      echo $message;
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#undefinedvariable

                                                                                                              Avoid using undefined variables such as '$parent_ids' which will lead to PHP notices.
                                                                                                              Open

                                                                                                                      $result = validateDeviceIds($parent_ids) ? $device->parents()->detach($parent_ids) : false;
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              UndefinedVariable

                                                                                                              Since: 2.8.0

                                                                                                              Detects when a variable is used that has not been defined before.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  private function bar()
                                                                                                                  {
                                                                                                                      // $message is undefined
                                                                                                                      echo $message;
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#undefinedvariable

                                                                                                              Avoid using undefined variables such as '$parent_ids' which will lead to PHP notices.
                                                                                                              Open

                                                                                                                          $parent_ids[] = $parent_id;
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              UndefinedVariable

                                                                                                              Since: 2.8.0

                                                                                                              Detects when a variable is used that has not been defined before.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  private function bar()
                                                                                                                  {
                                                                                                                      // $message is undefined
                                                                                                                      echo $message;
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#undefinedvariable

                                                                                                              Missing class import via use statement (line '2940', column '23').
                                                                                                              Open

                                                                                                                      $schema = new \LibreNMS\DB\Schema();
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '1557', column '32').
                                                                                                              Open

                                                                                                                  $result = json_decode((new \App\ApiClients\Oxidized())->getContent('/node/fetch/' . $node_info['full_name'] . '?format=json'), true);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '510', column '27').
                                                                                                              Open

                                                                                                                  $alert_schedule = new \App\Models\AlertSchedule([
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '858', column '22').
                                                                                                              Open

                                                                                                                  $COMPONENT = new LibreNMS\Component();
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '2439', column '27').
                                                                                                              Open

                                                                                                                  $alert_schedule = new \App\Models\AlertSchedule([
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '3119', column '21').
                                                                                                              Open

                                                                                                                  $location = new \App\Models\Location($data);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '871', column '22').
                                                                                                              Open

                                                                                                                  $COMPONENT = new LibreNMS\Component();
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '1556', column '35').
                                                                                                              Open

                                                                                                                  $node_info = json_decode((new \App\ApiClients\Oxidized())->getContent('/node/show/' . $hostname . '?format=json'), true);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '884', column '22').
                                                                                                              Open

                                                                                                                  $COMPONENT = new LibreNMS\Component();
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              Missing class import via use statement (line '844', column '26').
                                                                                                              Open

                                                                                                                      $COMPONENT = new LibreNMS\Component();
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              MissingImport

                                                                                                              Since: 2.7.0

                                                                                                              Importing all external classes in a file through use statements makes them clearly visible.

                                                                                                              Example

                                                                                                              function make() {
                                                                                                                  return new \stdClass();
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                                                              The method delete_components uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_error(500, 'Components could not be deleted.');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_bills uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $sql = '1';
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_bills uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                          } else {
                                                                                                                              $percent = '-';
                                                                                                                          }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_logs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          $query .= " AND $timestamp >= ?";
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_available_wireless_graphs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          foreach (dbFetchRows('SELECT `sensor_class` FROM `wireless_sensors` WHERE `device_id` = ? AND `sensor_deleted` = 0 GROUP BY `sensor_class`', [$device_id]) as $graph) {
                                                                                                                              $graphs[] = [
                                                                                                                                  'desc' => ucfirst($graph['sensor_class']),
                                                                                                                                  'name' => 'device_wireless_' . $graph['sensor_class'],
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method update_port_description uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      // Prevent poller from overwriting new description
                                                                                                                      set_dev_attrib($port, 'ifName:' . $ifName, 1); // see above
                                                                                                                      log_event("$ifName Port ifAlias set via API: $description", $device, 'interface', 3, $port_id);
                                                                                                              
                                                                                                              
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_logs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $query = ' FROM eventlog LEFT JOIN `devices` ON `eventlog`.`device_id`=`devices`.`device_id` WHERE 1';
                                                                                                                      $full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `eventlog`.*';
                                                                                                                      $timestamp = 'datetime';
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method create_edit_bill uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                          } else {
                                                                                                                              return $res;
                                                                                                                          }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method update_device uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_error(500, 'Device ' . $data['field'] . ' field failed to be updated');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_port_stack uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          $mappings = dbFetchRows("SELECT * FROM `ports_stack` WHERE `device_id` = ? AND `ifStackStatus` = 'active' ORDER BY `port_id_high`", [$device_id]);
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_inventory uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          $sql .= ' AND entPhysicalContainedIn="0"';
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_graph_generic_by_hostname uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          // If this isn't a wireless graph we need to fix the name.
                                                                                                                          $vars['type'] = str_replace('device_', 'sensor_', $vars['type']);
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_devices uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $sql = '1';
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_alerts uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $param = [1];
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method add_edit_rule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $mute = false;
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method update_device uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          return api_error(500, 'Device fields failed to be updated as the number of fields (' . count($data['field']) . ') does not match the supplied data (' . count($data['data']) . ')');
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method rename_device uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          return api_error(500, 'Device failed to be renamed');
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method update_device_port_notes uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_error(500, 'Port ' . $field . ' field failed to be updated');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method unmute_alert uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_success_noresult(200, 'No alert by that ID');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method create_edit_bill uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      // create new bill
                                                                                                                      if (array_key_exists('bill_id', $data)) {
                                                                                                                          return api_error(500, 'Argument bill_id is not allowed on bill create (auto assigned)');
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method update_device uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                          } else {
                                                                                                                              return api_error(500, 'Device fields failed to be updated');
                                                                                                                          }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_logs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          $query .= " AND $timestamp <= ?";
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method rename_device uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      if (renamehost($device_id, $new_hostname, 'api') == '') {
                                                                                                                          return api_success_noresult(200, 'Device has been renamed');
                                                                                                                      } else {
                                                                                                                          return api_error(500, 'Device failed to be renamed');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_graph_by_portgroup uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $if_list = $id;
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_available_health_graphs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                          } else {
                                                                                                                              foreach (dbFetchRows('SELECT `sensor_id`, `sensor_descr` FROM `sensors` WHERE `device_id` = ? AND `sensor_class` = ? AND `sensor_deleted` = 0', [$device_id, $type]) as $graph) {
                                                                                                                                  $graphs[] = [
                                                                                                                                      'sensor_id' => $graph['sensor_id'],
                                                                                                                                      'desc' => $graph['sensor_descr'],
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method search_oxidized uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_success($result, 'nodes');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_bills uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $select = "SELECT bills.*,
                                                                                                                          IF(bills.bill_type = 'cdr', bill_cdr, bill_quota) AS bill_allowed
                                                                                                                      ";
                                                                                                                      $query = "FROM `bills`\n";
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              Avoid assigning values to variables in if clauses and the like (line '1418', column '17').
                                                                                                              Open

                                                                                                              function add_edit_rule(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(500, "We couldn't parse the provided json");
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              IfStatementAssignment

                                                                                                              Since: 2.7.0

                                                                                                              Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($foo = 'bar') { // possible typo
                                                                                                                          // ...
                                                                                                                      }
                                                                                                                      if ($baz = 0) { // always false
                                                                                                                          // ...
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

                                                                                                              The method create_edit_bill uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                          } else {
                                                                                                                              return $res;
                                                                                                                          }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_arp uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $arp = dbFetchRows('SELECT * FROM `ipv4_mac` WHERE `ipv4_address`=?', [$query]);
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method maintenance_devicegroup uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_success_noresult(201, "Device group {$device_group->name} ({$device_group->id}) moved into maintenance mode" . ($duration ? " for {$duration}h" : ''));
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_available_health_graphs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          foreach (dbFetchRows('SELECT `sensor_class` FROM `sensors` WHERE `device_id` = ? AND `sensor_deleted` = 0 GROUP BY `sensor_class`', [$device_id]) as $graph) {
                                                                                                                              $graphs[] = [
                                                                                                                                  'desc' => ucfirst($graph['sensor_class']),
                                                                                                                                  'name' => 'device_' . $graph['sensor_class'],
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method add_edit_rule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $builder = $data['rule'];
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_bills uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                          } else {
                                                                                                                              $percent = '-';
                                                                                                                          }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method delete_rule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          return api_success_noresult(200, 'No alert rule by that ID');
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method ack_alert uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_success_noresult(200, 'No Alert by that ID');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_device_groups uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $query = DeviceGroup::query();
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method maintenance_device uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_success_noresult(201, "Device {$device->hostname} ({$device->device_id}) moved into maintenance mode" . ($duration ? " for {$duration}h" : ''));
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_oxidized uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                              } else {
                                                                                                                                  $value = $device->$field_type;
                                                                                                                              }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_bill_graphdata uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                      } else {
                                                                                                                          return api_success($graph_data, 'graph_data');
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method list_available_wireless_graphs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                          } else {
                                                                                                                              foreach (dbFetchRows('SELECT `sensor_id`, `sensor_descr` FROM `wireless_sensors` WHERE `device_id` = ? AND `sensor_class` = ? AND `sensor_deleted` = 0', [$device_id, $type]) as $graph) {
                                                                                                                                  $graphs[] = [
                                                                                                                                      'sensor_id' => $graph['sensor_id'],
                                                                                                                                      'desc' => $graph['sensor_descr'],
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_port_description uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_success($port->ifAlias, 'port_description');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method add_edit_rule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      $query = QueryBuilderParser::fromJson($builder)->toSql();
                                                                                                                      if (empty($query)) {
                                                                                                                          return api_error(500, "We couldn't parse your rule");
                                                                                                                      }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              The method get_oxidized_config uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                                                              Open

                                                                                                                  } else {
                                                                                                                      return api_success($result, 'config');
                                                                                                                  }
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ElseExpression

                                                                                                              Since: 1.4.0

                                                                                                              An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  public function bar($flag)
                                                                                                                  {
                                                                                                                      if ($flag) {
                                                                                                                          // one branch
                                                                                                                      } else {
                                                                                                                          // another branch
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/cleancode.html#elseexpression

                                                                                                              Avoid unused parameters such as '$request'.
                                                                                                              Open

                                                                                                              function list_ospf_ports(Illuminate\Http\Request $request)
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              UnusedFormalParameter

                                                                                                              Since: 0.2

                                                                                                              Avoid passing parameters to methods or constructors and then not using those parameters.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  private function bar($howdy)
                                                                                                                  {
                                                                                                                      // $howdy is not used
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

                                                                                                              Avoid unused local variables such as '$dummy'.
                                                                                                              Open

                                                                                                                          foreach ($missing as $missing_key => $dummy) {
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              UnusedLocalVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a local variable is declared and/or assigned, but not used.

                                                                                                              Example

                                                                                                              class Foo {
                                                                                                                  public function doSomething()
                                                                                                                  {
                                                                                                                      $i = 5; // Unused
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

                                                                                                              Avoid unused parameters such as '$request'.
                                                                                                              Open

                                                                                                              function get_port_groups(Illuminate\Http\Request $request)
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              UnusedFormalParameter

                                                                                                              Since: 0.2

                                                                                                              Avoid passing parameters to methods or constructors and then not using those parameters.

                                                                                                              Example

                                                                                                              class Foo
                                                                                                              {
                                                                                                                  private function bar($howdy)
                                                                                                                  {
                                                                                                                      // $howdy is not used
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

                                                                                                              FIXME found
                                                                                                              Open

                                                                                                                      // FIXME: Need to provide better diagnostics out of delete_device
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by fixme

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

                                                                                                              function update_device_group_add_devices(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 1 day to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2355..2390

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

                                                                                                              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

                                                                                                              function update_device_group_remove_devices(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  if (json_last_error() || ! is_array($data)) {
                                                                                                                      return api_error(400, "We couldn't parse the provided json. " . json_last_error_msg());
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 1 day to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2318..2353

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

                                                                                                              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

                                                                                                              function remove_port_group(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $port_group_id = $request->route('port_group_id');
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  $port_id_list = $data['port_ids'];
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 6 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2147..2169

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

                                                                                                              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

                                                                                                              function assign_port_group(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $port_group_id = $request->route('port_group_id');
                                                                                                                  $data = json_decode($request->getContent(), true);
                                                                                                                  $port_id_list = $data['port_ids'];
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 6 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2171..2193

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

                                                                                                              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

                                                                                                              function get_ports_by_group(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $name = $request->route('name');
                                                                                                                  if (! $name) {
                                                                                                                      return api_error(400, 'No port group name provided');
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 5 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2467..2487

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

                                                                                                              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

                                                                                                              function get_devices_by_group(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $name = $request->route('name');
                                                                                                                  if (! $name) {
                                                                                                                      return api_error(400, 'No device group name provided');
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 5 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2125..2145

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

                                                                                                              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

                                                                                                              function list_mpls_services(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $hostname = $request->get('hostname');
                                                                                                                  $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                              
                                                                                                              
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 3 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2554..2568

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

                                                                                                              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

                                                                                                              function list_mpls_saps(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $hostname = $request->get('hostname');
                                                                                                                  $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                              
                                                                                                              
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 3 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2538..2552

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

                                                                                                              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

                                                                                                              function device_outages(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  // return outages per device
                                                                                                              
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 3 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 543..562

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

                                                                                                              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

                                                                                                              function device_availability(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  // return availability per device
                                                                                                              
                                                                                                                  $hostname = $request->route('hostname');
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 3 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 564..583

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

                                                                                                              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

                                                                                                                  return check_device_permission($device_id, function ($device_id) {
                                                                                                                      $ipv4 = dbFetchRows('SELECT `ipv4_addresses`.* FROM `ipv4_addresses` JOIN `ports` ON `ports`.`port_id`=`ipv4_addresses`.`port_id` WHERE `ports`.`device_id` = ? AND `deleted` = 0', [$device_id]);
                                                                                                                      $ipv6 = dbFetchRows('SELECT `ipv6_addresses`.* FROM `ipv6_addresses` JOIN `ports` ON `ports`.`port_id`=`ipv6_addresses`.`port_id` WHERE `ports`.`device_id` = ? AND `deleted` = 0', [$device_id]);
                                                                                                                      $ip_addresses_count = count(array_merge($ipv4, $ipv6));
                                                                                                                      if ($ip_addresses_count == 0) {
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 2 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 1073..1082

                                                                                                              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

                                                                                                                  return check_port_permission($port_id, null, function ($port_id) {
                                                                                                                      $ipv4 = dbFetchRows('SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?', [$port_id]);
                                                                                                                      $ipv6 = dbFetchRows('SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?', [$port_id]);
                                                                                                                      $ip_addresses_count = count(array_merge($ipv4, $ipv6));
                                                                                                                      if ($ip_addresses_count == 0) {
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 2 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 1057..1066

                                                                                                              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

                                                                                                              function get_vrf(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $vrfId = $request->route('id');
                                                                                                                  if (! is_numeric($vrfId)) {
                                                                                                                      return api_error(400, 'Invalid id has been provided');
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 2 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2640..2654

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

                                                                                                              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

                                                                                                              function get_link(Illuminate\Http\Request $request)
                                                                                                              {
                                                                                                                  $linkId = $request->route('id');
                                                                                                                  if (! is_numeric($linkId)) {
                                                                                                                      return api_error(400, 'Invalid id has been provided');
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 2 hrs to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2522..2536

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

                                                                                                              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

                                                                                                              function list_ip_networks()
                                                                                                              {
                                                                                                                  $ipv4_networks = dbFetchRows('SELECT * FROM `ipv4_networks`');
                                                                                                                  $ipv6_networks = dbFetchRows('SELECT * FROM `ipv6_networks`');
                                                                                                                  $ip_networks_count = count(array_merge($ipv4_networks, $ipv6_networks));
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 1 hr to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2746..2756

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

                                                                                                              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

                                                                                                              function list_ip_addresses()
                                                                                                              {
                                                                                                                  $ipv4_addresses = dbFetchRows('SELECT * FROM `ipv4_addresses`');
                                                                                                                  $ipv6_addresses = dbFetchRows('SELECT * FROM `ipv6_addresses`');
                                                                                                                  $ip_addresses_count = count(array_merge($ipv4_addresses, $ipv6_addresses));
                                                                                                              Severity: Major
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 1 hr to fix
                                                                                                              includes/html/api_functions.inc.php on lines 2758..2768

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

                                                                                                              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

                                                                                                                  foreach (explode(',', $data['parent_ids']) as $hostname) {
                                                                                                                      $hostname = trim($hostname);
                                                                                                                      $parent_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                                      if (empty($parent_id)) {
                                                                                                                          return api_error(400, 'Parent device IDs/Hostname does not exist: ' . $hostname);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 40 mins to fix
                                                                                                              includes/html/api_functions.inc.php on lines 3077..3084

                                                                                                              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

                                                                                                                      foreach (explode(',', $data['parent_ids']) as $hostname) {
                                                                                                                          $hostname = trim($hostname);
                                                                                                                          $parent_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
                                                                                                                          if (empty($parent_id)) {
                                                                                                                              return api_error(400, 'Parent device IDs/Hostname does not exist: ' . $hostname);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php and 1 other location - About 40 mins to fix
                                                                                                              includes/html/api_functions.inc.php on lines 3049..3056

                                                                                                              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

                                                                                                              Avoid excessively long variable names like $total_ospf_neighbours. Keep variable name length under 20.
                                                                                                              Open

                                                                                                                  $total_ospf_neighbours = count($ospf_neighbours);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              LongVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, formal or local variable is declared with a long name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  protected $reallyLongIntName = -3; // VIOLATION - Field
                                                                                                                  public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                                                                                                                      $otherReallyLongName = -5; // VIOLATION - Local
                                                                                                                      for ($interestingIntIndex = 0; // VIOLATION - For
                                                                                                                           $interestingIntIndex < 10;
                                                                                                                           $interestingIntIndex++ ) {
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#longvariable

                                                                                                              Avoid excessively long variable names like $search_in_conf_textbox. Keep variable name length under 20.
                                                                                                              Open

                                                                                                                  $search_in_conf_textbox = $request->route('searchstring');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              LongVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, formal or local variable is declared with a long name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  protected $reallyLongIntName = -3; // VIOLATION - Field
                                                                                                                  public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                                                                                                                      $otherReallyLongName = -5; // VIOLATION - Local
                                                                                                                      for ($interestingIntIndex = 0; // VIOLATION - For
                                                                                                                           $interestingIntIndex < 10;
                                                                                                                           $interestingIntIndex++ ) {
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#longvariable

                                                                                                              Avoid variables with short names like $ip. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                          $ip = new IPv4("$query/$cidr");
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $id. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $id = $request->route('id');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $v. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $v = Validator::make($data, $rules);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $to. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $to = $request->get('to');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $v. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $v = Validator::make($data, $rules);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $id. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $id = $request->route('id');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $v. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $v = Validator::make($data, $rules);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $id. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $id = $request->route('id');
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $v. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $v = Validator::make($data, $rules);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $v. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $v = Validator::make($data, $rules);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $to. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                          $to = $request->get('to', time());
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Avoid variables with short names like $v. Configured minimum length is 3.
                                                                                                              Open

                                                                                                                  $v = Validator::make($data, $rules);
                                                                                                              Severity: Minor
                                                                                                              Found in includes/html/api_functions.inc.php by phpmd

                                                                                                              ShortVariable

                                                                                                              Since: 0.2

                                                                                                              Detects when a field, local, or parameter has a very short name.

                                                                                                              Example

                                                                                                              class Something {
                                                                                                                  private $q = 15; // VIOLATION - Field
                                                                                                                  public static function main( array $as ) { // VIOLATION - Formal
                                                                                                                      $r = 20 + $this->q; // VIOLATION - Local
                                                                                                                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                                                          $r += $this->q;
                                                                                                                      }
                                                                                                                  }
                                                                                                              }

                                                                                                              Source https://phpmd.org/rules/naming.html#shortvariable

                                                                                                              Space before opening parenthesis of function call prohibited
                                                                                                              Open

                                                                                                                      \App\Models\AlertRule::when($id, fn ($query) => $query->where('id', $id))

                                                                                                              There are no issues that match your filters.

                                                                                                              Category
                                                                                                              Status