CategoryGroup::deleteRecord()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NerdsAndCompany\Schematic\Converters\Models;
4
5
use Craft;
6
use craft\base\Model;
7
use craft\models\CategoryGroup_SiteSettings;
8
9
/**
10
 * Schematic Category Groups Converter.
11
 *
12
 * Sync Craft Setups.
13
 *
14
 * @author    Nerds & Company
15
 * @copyright Copyright (c) 2015-2019, Nerds & Company
16
 * @license   MIT
17
 *
18
 * @see      http://www.nerds.company
19
 */
20
class CategoryGroup extends Base
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    public function getRecordDefinition(Model $record): array
26
    {
27 2
        $definition = parent::getRecordDefinition($record);
28
29 2
        if ($record instanceof CategoryGroup_SiteSettings) {
30 2
            unset($definition['attributes']['groupId']);
31 2
            unset($definition['attributes']['siteId']);
32
        }
33
34 2
        return $definition;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 2
    public function saveRecord(Model $record, array $definition): bool
41
    {
42 2
        return Craft::$app->categories->saveGroup($record);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function deleteRecord(Model $record): bool
49
    {
50 2
        return Craft::$app->categories->deleteGroupById($record->id);
51
    }
52
}
53