ExportRepository::queue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace NovaExportConfiguration\Repositories;
4
5
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
6
use Illuminate\Foundation\Bus\PendingDispatch;
7
use Illuminate\Support\Str;
8
use NovaExportConfiguration\Export\ConfiguredExport;
9
use NovaExportConfiguration\Export\ExportQuery;
10
use NovaExportConfiguration\Export\NovaResourceConfig;
11
use NovaExportConfiguration\Models\ExportConfig;
12
use NovaResourceDynamicExport\Models\ExportStoredFile;
13
14
abstract class ExportRepository
15
{
16
    abstract public function name(): string;
17
18
    public function label(): string
19
    {
20
        return Str::ucfirst(Str::snake(Str::camel($this->name()), ' '));
21
    }
22
23
    public function disk(): string
24
    {
25
        return config('nova-export-configuration.defaults.disk');
26
    }
27
28
    public function queue(): string
29
    {
30
        return config('nova-export-configuration.defaults.queue');
31
    }
32
33
    abstract public function exportFileClass(): string;
34
35
    abstract public function exportQueryClass(): string;
36
37
    abstract public function novaResourceConfigClass(): string;
38
39
    public function exportFile(ExportConfig $model): ConfiguredExport
40
    {
41
        $exportFileClass = $this->exportFileClass();
42
43
        return new $exportFileClass($this->exportQuery($model));
44
    }
45
46
    public function exportQuery(ExportConfig $model): ExportQuery
47
    {
48
        $exportQueryClass = $this->exportQueryClass();
49
50
        return new $exportQueryClass($model);
51
    }
52
53
    public function novaResourceConfig(): NovaResourceConfig
54
    {
55
        $novaResourceConfigClass= $this->novaResourceConfigClass();
56
57
        return new $novaResourceConfigClass();
58
    }
59
60
    public function export(ExportConfig $model, ExportStoredFile $file): ConfiguredExport
61
    {
62
        return $this->exportFile($model)
63
                    ->useStoreFile($file)
64
                    ->setNotificationUser($file->meta->fromMorph('user'));
65
    }
66
67
    abstract public function isFilterKey(string $key): bool;
68
69
    abstract public function modelSetAttribute(ExportConfig $model, $key, $value);
70
71
    abstract public function modelGetAttribute(ExportConfig $model, $key);
72
73
    public function regenerateConfigurationData(ExportConfig $model, bool $persist): void
0 ignored issues
show
Unused Code introduced by
The parameter $persist 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

73
    public function regenerateConfigurationData(ExportConfig $model, /** @scrutinizer ignore-unused */ bool $persist): void

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...
74
    {
75
        if ($model->exists && $model->getKey() && $this->pivotRelation($model)) {
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->pivotRelation($model) targeting NovaExportConfiguration\...sitory::pivotRelation() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
76
            $this->rebuildAttachedPivots(dispatch(function () use ($model) {
77
                $pivotRelation = $this->pivotRelation($model);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $pivotRelation is correct as $this->pivotRelation($model) targeting NovaExportConfiguration\...sitory::pivotRelation() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
78
                $query         = $this->exportQuery($model)->query();
79
                $pivotRelation->detach();
80
                $query->select('id')
81
                      ->chunk(1000, function ($models) use ($pivotRelation) {
82
                          $pivotRelation->syncWithoutDetaching($models->pluck('id')->toArray());
83
                      });
84
            }));
85
        }
86
    }
87
88
    protected function pivotRelation(ExportConfig $model): ?BelongsToMany
0 ignored issues
show
Unused Code introduced by
The parameter $model 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

88
    protected function pivotRelation(/** @scrutinizer ignore-unused */ ExportConfig $model): ?BelongsToMany

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...
89
    {
90
        return null;
91
    }
92
93
    protected function rebuildAttachedPivots(PendingDispatch $pendingDispatch): void
0 ignored issues
show
Unused Code introduced by
The parameter $pendingDispatch 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

93
    protected function rebuildAttachedPivots(/** @scrutinizer ignore-unused */ PendingDispatch $pendingDispatch): void

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...
94
    {
95
    }
96
}
97