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

Apps/Controller/Admin/Content/ActionGlobDelete.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Apps\Controller\Admin\Content;
4
5
use Apps\ActiveRecord\Content as ContentEntity;
6
use Apps\Model\Admin\Content\FormContentGlobDelete;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\NotFoundException;
10
use Ffcms\Core\Helper\Type\Any;
11
use Ffcms\Core\Network\Request;
12
use Ffcms\Core\Network\Response;
13
14
/**
15
 * Trait ActionGlobDelete
16
 * @package Apps\Controller\Admin\Content
17
 * @property Request $request
18
 * @property Response $response
19
 * @property View $view
20
 */
21
trait ActionGlobDelete
22
{
23
    /**
24
     * Show content global delete
25
     * @return string
26
     * @throws NotFoundException
27
     * @throws \Ffcms\Core\Exception\SyntaxException
28
     */
29
    public function globDelete(): ?string
30
    {
31
        // get content ids from request
32
        $ids = $this->request->query->get('selected');
33
34
        // check if input is array
35
        if (!Any::isArray($ids) || count($ids) < 1) {
36
            throw new NotFoundException(__('Nothing to delete is founded'));
37
        }
38
39
        // get all records as object from db
40
        $records = ContentEntity::find($ids);
41
        if ($records->count() < 1) {
42
            throw new NotFoundException(__('Nothing to delete is founded'));
43
        }
44
45
        // init model and pass objects
46
        $model = new FormContentGlobDelete($records);
0 ignored issues
show
It seems like $records can also be of type Apps\ActiveRecord\Content; however, parameter $records of Apps\Model\Admin\Content...obDelete::__construct() does only seem to accept Apps\ActiveRecord\Conten...ase\Eloquent\Collection, maybe add an additional type check? ( Ignorable by Annotation )

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

46
        $model = new FormContentGlobDelete(/** @scrutinizer ignore-type */ $records);
Loading history...
47
48
        // check if delete is submited
49
        if ($model->send() && $model->validate()) {
50
            $model->make();
51
            App::$Session->getFlashBag()->add('success', __('Content are successful removed'));
52
            $this->response->redirect('content/index');
53
        }
54
55
        // return response
56
        return $this->view->render('content/content_glob_delete', [
57
            'model' => $model
58
        ]);
59
    }
60
}
61