Completed
Pull Request — master (#52)
by Gino
01:54
created

Series   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 24.49 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 12
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A update() 12 12 2

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 BackendMenu;
6
use Backend\Classes\Controller;
7
use GinoPane\BlogTaxonomy\Models\Series as SeriesModel;
8
use GinoPane\BlogTaxonomy\Plugin;
9
use Backend\Behaviors\FormController;
10
use Backend\Behaviors\ListController;
11
use Backend\Behaviors\RelationController;
12
13
/**
14
 * Class Series
15
 *
16
 * @package GinoPane\BlogTaxonomy\Controllers
17
 */
18
class Series extends Controller
19
{
20
    /**
21
     * Behaviours implemented by the controller
22
     *
23
     * @var array
24
     */
25
    public $implement = [
26
        FormController::class,
27
        ListController::class,
28
        RelationController::class
29
    ];
30
31
    public $formConfig = 'config_form.yaml';
32
    public $listConfig = 'config_list.yaml';
33
    public $relationConfig = 'config_relation.yaml';
34
35
    /**
36
     * Series constructor
37
     */
38
    public function __construct()
39
    {
40
        parent::__construct();
41
42
        BackendMenu::setContext(Plugin::REQUIRED_PLUGIN_RAINLAB_BLOG, 'blog', 'series');
43
    }
44
45
    /**
46
     * Controller "update" action used for updating existing model records.
47
     * This action takes a record identifier (primary key of the model)
48
     * to locate the record used for sourcing the existing form values.
49
     *
50
     * @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...
51
     * @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...
52
     * @return void
53
     */
54 View Code Duplication
    public function update($recordId = null, $context = null)
0 ignored issues
show
Duplication introduced by
This method 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...
55
    {
56
        $series = SeriesModel::whereId($recordId)->first();
57
58
        if ($series !== null) {
59
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.series.edit_title', ['series' => $series->title]);
60
        } else {
61
            $this->pageTitle = trans(Plugin::LOCALIZATION_KEY . 'form.series.series_does_not_exist');
62
        }
63
64
        return $this->asExtension('FormController')->update($recordId, $context);
65
    }
66
}
67