Series   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 71
loc 71
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 12 12 2
A onBulkDelete() 16 16 3
A __construct() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace GinoPane\BlogTaxonomy\Controllers;
4
5
use Flash;
6
use BackendMenu;
7
use Backend\Classes\Controller;
8
use GinoPane\BlogTaxonomy\Plugin;
9
use Backend\Behaviors\FormController;
10
use Backend\Behaviors\ListController;
11
use Backend\Behaviors\RelationController;
12
use GinoPane\BlogTaxonomy\Models\Series as SeriesModel;
13
14
/**
15
 * Class Series
16
 *
17
 * @package GinoPane\BlogTaxonomy\Controllers
18
 */
19 View Code Duplication
class Series extends Controller
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * Behaviours implemented by the controller
23
     *
24
     * @var array
25
     */
26
    public $implement = [
27
        FormController::class,
28
        ListController::class,
29
        RelationController::class
30
    ];
31
32
    public $formConfig = 'config_form.yaml';
33
    public $listConfig = 'config_list.yaml';
34
    public $relationConfig = 'config_relation.yaml';
35
36
    /**
37
     * Series constructor
38
     */
39
    public function __construct()
40
    {
41
        parent::__construct();
42
43
        BackendMenu::setContext(Plugin::REQUIRED_PLUGIN_RAINLAB_BLOG, 'blog', 'series');
44
    }
45
46
    /**
47
     * Controller "update" action used for updating existing model records.
48
     * This action takes a record identifier (primary key of the model)
49
     * to locate the record used for sourcing the existing form values.
50
     *
51
     * @param int $recordId Record identifier
0 ignored issues
show
Documentation introduced by
Should the type for parameter $recordId not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
52
     * @param string $context Form context
0 ignored issues
show
Documentation introduced by
Should the type for parameter $context not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
53
     * @return void
54
     */
55
    public function update($recordId = null, $context = null)
56
    {
57
        $series = SeriesModel::whereId($recordId)->first();
58
59
        if ($series !== null) {
60
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.series.edit_title', ['series' => $series->title]);
61
        } else {
62
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.series.series_does_not_exist');
63
        }
64
65
        return $this->asExtension('FormController')->update($recordId, $context);
66
    }
67
68
    /**
69
     * Remove multiple tags
70
     *
71
     * @return mixed
72
     */
73
    public function onBulkDelete()
74
    {
75
        if ($checkedIds = (array)post('checked', [])) {
76
            $delete = SeriesModel::whereIn('id', $checkedIds)->delete();
77
        }
78
79
        if (empty($delete)) {
80
            Flash::error(e(trans(Plugin::LOCALIZATION_KEY . 'form.errors.unknown')));
81
82
            return;
83
        }
84
85
        Flash::success(e(trans(Plugin::LOCALIZATION_KEY . 'form.series.delete_series_success')));
86
87
        return $this->listRefresh();
88
    }
89
}
90