arkaitzgarro/elastic-apm-laravel

View on GitHub
src/Middleware/RecordTransaction.php

Summary

Maintainability
A
0 mins
Test Coverage
A
96%

getRequestUri accesses the super-global variable $_SERVER.
Open

    protected function getRequestUri(): string
    {
        // Fallback to script file name, like index.php when URI is not provided
        return parse_url($_SERVER['REQUEST_URI'] ?? null, PHP_URL_PATH) ?? $_SERVER['SCRIPT_FILENAME'];
    }
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

getRequestUri accesses the super-global variable $_SERVER.
Open

    protected function getRequestUri(): string
    {
        // Fallback to script file name, like index.php when URI is not provided
        return parse_url($_SERVER['REQUEST_URI'] ?? null, PHP_URL_PATH) ?? $_SERVER['SCRIPT_FILENAME'];
    }
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

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

            Log::error($t->getMessage());
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 method getRouteUriTransactionName uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $uri = $this->getRequestUri();
        }
Severity: Minor
Found in src/Middleware/RecordTransaction.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 property $start_time is not named in camelCase.
Open

class RecordTransaction
{
    protected $agent;
    protected $config;
    protected $start_time;
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

CamelCasePropertyName

Since: 0.2

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

Example

class ClassName {
    protected $property_name;
}

Source

The parameter $transaction_name is not named in camelCase.
Open

    protected function shouldIgnoreTransaction(string $transaction_name): bool
    {
        $pattern = $this->config->get('elastic-apm-laravel.transactions.ignorePatterns');

        return $pattern && preg_match($pattern, $transaction_name);
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $start_time is not named in camelCase.
Open

    public function __construct(Agent $agent, Config $config, RequestStartTime $start_time)
    {
        $this->agent = $agent;
        $this->config = $config;
        $this->start_time = $start_time;
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $transaction_name is not named in camelCase.
Open

    protected function startTransaction(string $transaction_name): Transaction
    {
        return $this->agent->startTransaction(
            $transaction_name,
            [],
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

CamelCaseParameterName

Since: 0.2

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

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The variable $transaction_name is not named in camelCase.
Open

    public function handle(Request $request, \Closure $next)
    {
        $transaction_name = $this->getTransactionName($request);

        if ($this->shouldIgnoreTransaction($transaction_name)) {
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    public function terminate(Request $request): void
    {
        $transaction_name = $this->getTransactionName($request);

        if ($this->shouldIgnoreTransaction($transaction_name)) {
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    public function terminate(Request $request): void
    {
        $transaction_name = $this->getTransactionName($request);

        if ($this->shouldIgnoreTransaction($transaction_name)) {
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    public function handle(Request $request, \Closure $next)
    {
        $transaction_name = $this->getTransactionName($request);

        if ($this->shouldIgnoreTransaction($transaction_name)) {
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $start_time is not named in camelCase.
Open

    public function __construct(Agent $agent, Config $config, RequestStartTime $start_time)
    {
        $this->agent = $agent;
        $this->config = $config;
        $this->start_time = $start_time;
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    public function terminate(Request $request): void
    {
        $transaction_name = $this->getTransactionName($request);

        if ($this->shouldIgnoreTransaction($transaction_name)) {
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    public function terminate(Request $request): void
    {
        $transaction_name = $this->getTransactionName($request);

        if ($this->shouldIgnoreTransaction($transaction_name)) {
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    protected function shouldIgnoreTransaction(string $transaction_name): bool
    {
        $pattern = $this->config->get('elastic-apm-laravel.transactions.ignorePatterns');

        return $pattern && preg_match($pattern, $transaction_name);
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    public function handle(Request $request, \Closure $next)
    {
        $transaction_name = $this->getTransactionName($request);

        if ($this->shouldIgnoreTransaction($transaction_name)) {
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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 $transaction_name is not named in camelCase.
Open

    protected function startTransaction(string $transaction_name): Transaction
    {
        return $this->agent->startTransaction(
            $transaction_name,
            [],
Severity: Minor
Found in src/Middleware/RecordTransaction.php by phpmd

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