HasFeatureImage   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 13
c 1
b 0
f 0
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createFeatureImageManager() 0 8 3
A featureImageManager() 0 5 1
A featureImageKey() 0 3 2
A featureImageManagerDirectory() 0 7 2
1
<?php
2
3
4
namespace NovaThinKit\FeatureImage\Models;
5
6
use Illuminate\Support\Str;
7
use NovaThinKit\FeatureImage\FeatureImageManager;
8
use NovaThinKit\FeatureImage\ImageManager;
9
10
trait HasFeatureImage
11
{
12
    protected ?ImageManager $featureImageManager = null;
13
14 1
    protected function createFeatureImageManager(?string $tag = null): ImageManager
0 ignored issues
show
Unused Code introduced by
The parameter $tag is not used and could be removed. ( Ignorable by Annotation )

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

14
    protected function createFeatureImageManager(/** @scrutinizer ignore-unused */ ?string $tag = null): ImageManager

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
    {
16 1
        if (!$this->featureImageManager) {
17 1
            $featureImageManagerConfig = property_exists($this, 'featureImageManagerConfig') ? $this->featureImageManagerConfig : 'nova-thinkit.feature-images.default';
18 1
            $this->featureImageManager = FeatureImageManager::fromConfig(config($featureImageManagerConfig));
19
        }
20
21 1
        return $this->featureImageManager;
22
    }
23
24 17
    public function featureImageManager(?string $tag = null): ImageManager
25
    {
26 17
        return $this->createFeatureImageManager($tag)
27 17
            ->setTag($tag)
0 ignored issues
show
Bug introduced by
The method setTag() does not exist on NovaThinKit\FeatureImage\ImageManager. Since it exists in all sub-types, consider adding an abstract or default implementation to NovaThinKit\FeatureImage\ImageManager. ( Ignorable by Annotation )

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

27
            ->/** @scrutinizer ignore-call */ setTag($tag)
Loading history...
28 17
            ->setModel($this);
29
    }
30
31
32 1
    public function featureImageManagerDirectory(?string $tag = null): string
0 ignored issues
show
Unused Code introduced by
The parameter $tag is not used and could be removed. ( Ignorable by Annotation )

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

32
    public function featureImageManagerDirectory(/** @scrutinizer ignore-unused */ ?string $tag = null): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34 1
        $class = $this->getMorphClass();
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() 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

34
        /** @scrutinizer ignore-call */ 
35
        $class = $this->getMorphClass();
Loading history...
35
36 1
        $path = Str::contains($class, '\\') ? class_basename($class) : $class;
37
38 1
        return base64_encode($path . '-' . $this->getKey());
0 ignored issues
show
Bug introduced by
It seems like getKey() 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

38
        return base64_encode($path . '-' . $this->/** @scrutinizer ignore-call */ getKey());
Loading history...
39
    }
40
41 3
    public function featureImageKey(?string $tag = null): string
42
    {
43 3
        return $tag ?: 'image';
44
    }
45
}
46