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

NodeDrupal8::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Drupal\Driver\Plugin\DriverEntity;
4
5
use Drupal\Driver\Plugin\DriverEntityPluginDrupal8Base;
6
7
/**
8
 * A driver field plugin used to test selecting an arbitrary plugin.
9
 *
10
 * @DriverEntity(
11
 *   id = "node8",
12
 *   version = 8,
13
 *   weight = -100,
14
 *   entityTypes = {
15
 *     "node",
16
 *   },
17
 * )
18
 */
19 View Code Duplication
class NodeDrupal8 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...
20
21
  /**
22
   * The id of the attached node.
23
   *
24
   * @var int
25
   *
26
   * @deprecated Use id() instead.
27
   */
28
  public $nid;
29
30
  /**
31
   * {@inheritdoc}
32
   */
33
  public function load($entityId) {
34
    $entity = parent::load($entityId);
35
    $this->nid = is_null($this->entity) ? NULL : $this->id();
0 ignored issues
show
Documentation Bug introduced by
It seems like is_null($this->entity) ? NULL : $this->id() can also be of type string. However, the property $nid is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Deprecated Code introduced by
The property Drupal\Driver\Plugin\Dri...ntity\NodeDrupal8::$nid 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...
36
    return $entity;
37
  }
38
39
  /**
40
   * {@inheritdoc}
41
   */
42
  public function save() {
43
    parent::save();
44
    $this->nid = $this->id();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->id() can also be of type string. However, the property $nid is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Deprecated Code introduced by
The property Drupal\Driver\Plugin\Dri...ntity\NodeDrupal8::$nid 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...
45
  }
46
47
  /**
48
   * {@inheritdoc}
49
   */
50
  public function set($identifier, $field) {
51
    if ($identifier === 'author') {
52
      $identifier = 'uid';
53
    }
54
    parent::set($identifier, $field);
55
  }
56
57
}
58