WithImages   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 26
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A bootWithImages() 0 5 1
A images() 0 3 1
A image() 0 3 1
A bindImage() 0 3 1
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "WithImages.php" doesn't match the expected filename "withimages.php"
Loading history...
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace UniSharp\Uploadable\Traits;
4
5
use UniSharp\Uploadable\File;
6
use UniSharp\Uploadable\Image;
7
use Illuminate\Database\Eloquent\Relations\MorphOne;
8
use Illuminate\Database\Eloquent\Relations\MorphMany;
9
10
trait WithImages
0 ignored issues
show
Coding Style introduced by
Missing class doc comment
Loading history...
11
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for trait WithImages
Loading history...
12
    use Helpers;
13
14
    public static function bootWithImages(): void
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
15
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
16
        static::deleted(function ($model) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
17 4
            $model->images->each(function ($image) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
18
                $image->delete();
19 4
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
20 6
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
21 2
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end bootWithImages()
Loading history...
22
23 6
    public function image(): MorphOne
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
24
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
25 6
        return $this->morphOne(Image::class, 'uploadable')->whereNull('extra')->latest('id');
0 ignored issues
show
Bug introduced by
It seems like morphOne() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        return $this->/** @scrutinizer ignore-call */ morphOne(Image::class, 'uploadable')->whereNull('extra')->latest('id');
Loading history...
26
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end image()
Loading history...
27
28 6
    public function images(): MorphMany
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
29
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
30 6
        return $this->morphMany(Image::class, 'uploadable');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return $this->/** @scrutinizer ignore-call */ morphMany(Image::class, 'uploadable');
Loading history...
31
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end images()
Loading history...
32
33 2
    public function bindImage(File $image, $extra = null): self
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
34
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
35 2
        return $this->bindUploadable($image, $extra);
36
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end bindImage()
Loading history...
37
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
38