alientronics/fleetany-web

View on GitHub
app/Repositories/VehicleRepositoryEloquent.php

Summary

Maintainability
C
1 day
Test Coverage

File VehicleRepositoryEloquent.php has 255 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace App\Repositories;

use Prettus\Repository\Eloquent\BaseRepository;
Severity: Minor
Found in app/Repositories/VehicleRepositoryEloquent.php - About 2 hrs to fix

    Method getTireAndSensorData has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getTireAndSensorData($inputs)
        {
            $tire = Part::join('types', 'parts.part_type_id', '=', 'types.id')
                ->where('parts.position', $inputs['position'])
                ->where('parts.vehicle_id', $inputs['vehicle_id'])
    Severity: Minor
    Found in app/Repositories/VehicleRepositoryEloquent.php - About 1 hr to fix

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

          public static function getVehiclesStatistics()
          {
              $vehicles['in_use']['color'] = '#3871cf';
              $vehicles['in_use']['result'] = Vehicle::join('trips', 'vehicles.id', '=', 'trips.vehicle_id')
                      ->where('vehicles.company_id', Auth::user()['company_id'])
      Severity: Minor
      Found in app/Repositories/VehicleRepositoryEloquent.php - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                if (!empty($inputs['geofence_name']) &&
                    !empty($inputs['geofence_radius']) && is_numeric($inputs['geofence_radius']) &&
                    !empty($inputs['geofence_latitude']) && is_numeric($inputs['geofence_latitude']) &&
                    !empty($inputs['geofence_longitude']) && is_numeric($inputs['geofence_longitude'])
                ) {
        Severity: Major
        Found in app/Repositories/VehicleRepositoryEloquent.php - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                  if (!empty($tiresData['parts'][$sensor->part_id])
                      && ($sensor->pressure > $tiresData['dangerMaxPressure']
                          || $sensor->pressure < $tiresData['dangerMinPressure']
                          || $sensor->temperature > (int)config('app.tires_danger_temperature'))
                      ) {
          Severity: Major
          Found in app/Repositories/VehicleRepositoryEloquent.php - About 1 hr to fix

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

                private static function getVehiclesGeofence($vehicles)
                {
                    if (!empty($vehicles)) {
                        foreach ($vehicles as $index => $vehicle) {
                            if (empty($vehicle['geofence'])) {
            Severity: Minor
            Found in app/Repositories/VehicleRepositoryEloquent.php - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

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

                protected function setTiresColor($tiresData, $sensor, $objTire)
                {
                    if (!empty($tiresData['parts'][$sensor->part_id])
                        && ($sensor->pressure > $tiresData['dangerMaxPressure']
                            || $sensor->pressure < $tiresData['dangerMinPressure']
            Severity: Minor
            Found in app/Repositories/VehicleRepositoryEloquent.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

            There are no issues that match your filters.

            Category
            Status