Completed
Pull Request — master (#157)
by
unknown
01:50
created

TaxonomyTermDrupal8   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 45
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 6 6 2
A save() 5 5 1
A getBundleKeyLabels() 10 10 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
namespace Drupal\Driver\Plugin\DriverEntity;
3
4
use Drupal\Driver\Plugin\DriverEntityPluginDrupal8Base;
5
6
/**
7
 * A driver field plugin used to test selecting an arbitrary plugin.
8
 *
9
 * @DriverEntity(
10
 *   id = "taxonomy_term8",
11
 *   version = 8,
12
 *   weight = -100,
13
 *   entityTypes = {
14
 *     "taxonomy_term",
15
 *   },
16
 * )
17
 */
18 View Code Duplication
class TaxonomyTermDrupal8 extends DriverEntityPluginDrupal8Base
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...
19
{
20
21
  /**
22
   * The id of the attached term.
23
   *
24
   * @var integer;
25
   *
26
   * @deprecated Use id() instead.
27
   */
28
    public $tid;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function load($entityId)
34
    {
35
        $entity = parent::load($entityId);
36
        $this->tid = is_null($this->entity) ? NULL : $this->id();
0 ignored issues
show
Deprecated Code introduced by
The property Drupal\Driver\Plugin\Dri...xonomyTermDrupal8::$tid has been deprecated with message: Use id() instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
37
        return $entity;
38
    }
39
40
  /**
41
   * {@inheritdoc}
42
   */
43
    public function save()
44
    {
45
        parent::save();
46
        $this->tid = $this->id();
0 ignored issues
show
Deprecated Code introduced by
The property Drupal\Driver\Plugin\Dri...xonomyTermDrupal8::$tid has been deprecated with message: Use id() instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
47
    }
48
49
  /**
50
   * {@inheritdoc}
51
   */
52
    public function getBundleKeyLabels()
53
    {
54
        // Previously we made 'vocabulary_machine_name' available as a more
55
        // human-friendly alternative to 'vid' for the bundle field identifier.
56
        // This is now unnecessary as the label 'vocabulary' is available
57
        // automatically, but it is supported here for backwards-compatibility.
58
        $bundleKeyLabels = parent::getBundleKeyLabels();
59
        $bundleKeyLabels[] = 'vocabulary_machine_name';
60
        return $bundleKeyLabels;
61
    }
62
}
63