alientronics/fleetany-api

View on GitHub
app/Http/Controllers/TireSensorController.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method getPart has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function getPart($user, $json, $inputs)
    {
        $part = Part::select('id')->where('number', $json['id'])
            ->where('company_id', $user->company_id)
            ->first();
Severity: Minor
Found in app/Http/Controllers/TireSensorController.php - About 1 hr to fix

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

        public function create(Request $request)
        {
            $inputs = $request->all();
                
            if (!empty($inputs['json'])) {
    Severity: Minor
    Found in app/Http/Controllers/TireSensorController.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

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

            return (new \Illuminate\Http\Response)->setStatusCode(200);

    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

    Avoid using static access to class '\Illuminate\Support\Facades\Log' in method 'checkTireCondition'.
    Open

                Log::info('Alert Error: '.$e->getMessage());

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Entities\Part' in method 'getPart'.
    Open

                $partTire = Part::forceCreate([
                    "company_id" => $user->company_id,
                    "part_type_id" => $tireType->id,
                    "part_model_id" => $tireModel->id,
                    "number" => $json['id']."-tire",

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\Illuminate\Support\Facades\Log' in method 'create'.
    Open

            Log::info('TireSensor Data: '.json_encode($inputs));

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Entities\TireSensor' in method 'index'.
    Open

            $TireSensor = TireSensor::all();

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Entities\TireSensor' in method 'create'.
    Open

                        $tireSensor = TireSensor::forceCreate(["latitude" => $this->validateNumeric($json['latitude']),
                            "longitude" => $this->validateNumeric($json['longitude']),
                            //"created_at" => ( $this->validateDate($json['ts']) ?
                            //    $json['ts'] : \DB::raw('NOW()') ),
                            "number" => $json['id'],

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class '\App\Entities\Part' in method 'getPart'.
    Open

                $part = Part::forceCreate([
                    "company_id" => $user->company_id,
                    "part_type_id" => $sensorType->id,
                    "part_model_id" => $sensorModel->id,
                    "number" => $json['id'],

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    The variable $TireSensor is not named in camelCase.
    Open

        public function index()
        {
      
            $TireSensor = TireSensor::all();
      

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $TireSensor is not named in camelCase.
    Open

        public function index()
        {
      
            $TireSensor = TireSensor::all();
      

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status