DelModel   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A delete() 0 13 2
1
<?php
2
3
namespace Rudolf\Modules\Galleries\One\Admin;
4
5
use Rudolf\Framework\Model\AdminModel;
6
use Rudolf\Component\Modules\Module;
7
use Rudolf\Modules\Galleries\One;
8
9
class DelModel extends AdminModel
10
{
11
    /**
12
     * Delete gallery.
13
     *
14
     * @param int $id gallery ID
15
     *
16
     * @return bool
17
     * @throws \Exception
18
     */
19
    public function delete($id)
20
    {
21
        $query = $this->pdo->prepare("DELETE FROM {$this->prefix}galleries WHERE id = :id");
22
        $query->bindValue(':id', $id, \PDO::PARAM_INT);
23
24
        $f = (new One\Model())->getGalleryInfoById($id);
25
        $config = (new Module('galleries'))->getConfig();
26
        $directory = $config['path_root'].'/'.$f['slug'];
27
        array_map('unlink', glob($directory.'/*'));
28
        is_dir($directory) && rmdir($directory);
29
30
        return $query->execute();
31
    }
32
}
33