Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

FormContentClear::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Apps\Model\Admin\Content;
4
5
use Apps\ActiveRecord\Content;
6
use Ffcms\Core\Arch\Model;
7
use Ffcms\Core\Helper\FileSystem\Directory;
8
use Illuminate\Database\Eloquent\Collection;
9
10
class FormContentClear extends Model
11
{
12
    public $count = 0;
13
14
    /** @var Content|Collection */
15
    private $_records;
16
17
    /**
18
     * FormContentClear constructor. Pass content records collection object inside (can be empty collection)
19
     * @param Content|Collection $records
20
     */
21
    public function __construct($records)
22
    {
23
        $this->_records = $records;
24
        $this->count = $this->_records->count();
25
        parent::__construct();
26
    }
27
28
    /**
29
     * Form display labels
30
     * @return array
31
     */
32
    public function labels(): array
33
    {
34
        return [
35
            'count' => __('Trashed content')
36
        ];
37
    }
38
39
    /**
40
     * Finally delete content item
41
     */
42
    public function make()
43
    {
44
        // remove gallery files if exists
45
        foreach ($this->_records->get() as $record) {
0 ignored issues
show
Bug introduced by
The call to Illuminate\Support\Collection::get() has too few arguments starting with key. ( Ignorable by Annotation )

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

45
        foreach ($this->_records->/** @scrutinizer ignore-call */ get() as $record) {

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
46
            $galleryPath = '/upload/gallery/' . (int)$record->id;
47
            if (Directory::exist($galleryPath)) {
48
                Directory::remove($galleryPath);
49
            }
50
        }
51
52
        // finally remove from db
53
        $this->_records->forceDelete();
54
    }
55
}
56