Completed
Pull Request — master (#421)
by Robbie
02:31
created

BlogCategory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 57
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getListUrlSegment() 4 4 1
A getDuplicateError() 4 4 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 SilverStripe\Blog\Model;
4
5
use SilverStripe\Blog\Model\BlogObject;
6
use SilverStripe\Blog\Model\CategorisationObject;
7
use SilverStripe\ORM\DataObject;
8
9
/**
10
 * A blog category for generalising blog posts.
11
 *
12
 * @package silverstripe
13
 * @subpackage blog
14
 *
15
 * @method Blog Blog()
16
 *
17
 * @property string $Title
18
 * @property string $URLSegment
19
 * @property int $BlogID
20
 */
21 View Code Duplication
class BlogCategory extends DataObject implements CategorisationObject
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...
22
{
23
    use BlogObject;
24
25
    /**
26
     * Use an exception code so that attempted writes can continue on
27
     * duplicate errors.
28
     *
29
     * @const string
30
     * This must be a string because ValidationException has decided we can't use int
31
     */
32
    const DUPLICATE_EXCEPTION = 'DUPLICATE';
33
34
    /**
35
     * {@inheritDoc}
36
     * @var string
37
     */
38
    private static $table_name = 'BlogCategory';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $table_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
39
40
    /**
41
     * @var array
42
     */
43
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
44
        'Title'      => 'Varchar(255)',
45
        'URLSegment' => 'Varchar(255)'
46
    );
47
48
    /**
49
     * @var array
50
     */
51
    private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
52
        'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
53
    );
54
55
    /**
56
     * @var array
57
     */
58
    private static $belongs_many_many = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $belongs_many_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
59
        'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost',
60
    );
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    protected function getListUrlSegment()
66
    {
67
        return 'category';
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected function getDuplicateError()
74
    {
75
        return _t('BlogCategory.Duplicate', 'A blog category already exists with that name.');
76
    }
77
}
78