Strimoid/Strimoid

View on GitHub
app/Helpers/OEmbed.php

Summary

Maintainability
A
25 mins
Test Coverage

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

    protected function processData($data): ?string
    {
        if (array_key_exists('html', $data)) {
            return $data['html'];
        }
Severity: Minor
Found in app/Helpers/OEmbed.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 method getEmbedHtml has a boolean flag argument $autoPlay, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getEmbedHtml(string $url, bool $autoPlay = true)
Severity: Minor
Found in app/Helpers/OEmbed.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

Avoid using static access to class '\Illuminate\Support\Str' in method 'embedMedia'.
Open

            if (Str::startsWith($link['type'], $mimetype)) {
Severity: Minor
Found in app/Helpers/OEmbed.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

Avoid using static access to class '\Strimoid\Facades\Guzzle' in method 'getData'.
Open

        $response = Guzzle::get($this->endpoint(), compact('query'));
Severity: Minor
Found in app/Helpers/OEmbed.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

Avoid using static access to class '\Illuminate\Support\Facades\Cache' in method 'getEmbedHtml'.
Open

        return Cache::rememberForever($key, function () use ($url, $autoPlay) {
            try {
                return $this->fetchEmbedCode($url, $autoPlay);
            } catch (\Throwable $throwable) {
                Log::warning('Failed to fetch embed code: ' . $throwable->getMessage());
Severity: Minor
Found in app/Helpers/OEmbed.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

Avoid using static access to class '\Illuminate\Support\Str' in method 'isImage'.
Open

        if (in_array('file', $rel) && Str::startsWith($type, 'image')) {
Severity: Minor
Found in app/Helpers/OEmbed.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

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

                Log::warning('Failed to fetch embed code: ' . $throwable->getMessage());
Severity: Minor
Found in app/Helpers/OEmbed.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

Avoid using static access to class '\Illuminate\Support\Arr' in method 'getThumbnails'.
Open

        return Arr::pluck($images, 'href');
Severity: Minor
Found in app/Helpers/OEmbed.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

Avoid using static access to class '\Illuminate\Support\Arr' in method 'getThumbnail'.
Open

            $thumbnail = Arr::first($images);
Severity: Minor
Found in app/Helpers/OEmbed.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

There are no issues that match your filters.

Category
Status