Completed
Push — master ( 3cca65...6ffe9e )
by Gabriel
05:45
created

MergeTagsRecordTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 35.7%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 46
ccs 5
cts 14
cp 0.357
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setVars() 0 10 2
A getVars() 0 4 1
1
<?php
2
3
namespace Nip\MailModule\Models\EmailsTable\Traits\MergeTags;
4
5
use Nip\Mail\Models\MergeTags\RecordTrait as MailMergeTagsRecordTrait;
6
7
/**
8
 * Trait MergeTagsRecordTrait
9
 * @package Nip\MailModule\Models\EmailsTable\Traits\MergeTags
10
 */
11
trait MergeTagsRecordTrait
12
{
13
    use MailMergeTagsRecordTrait {
14
        generateMergeTags as generateMergeTagsTrait;
15
    }
16
17
    /**
18
     * @param $vars
19
     * @return $this
20
     */
21 2
    public function setVars($vars)
22
    {
23 2
        if (is_string($vars)) {
24 1
            $this->setDataValue('vars', $vars);
0 ignored issues
show
Bug introduced by
It seems like setDataValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
25
        } else {
26 2
            $this->mergeTags = $vars;
27
        }
28
29 2
        return $this;
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    public function getVars()
36
    {
37
        return $this->getMergeTags();
38
    }
39
40
    /**
41
     * @inheritdoc
42
     * Used to decode html entities to proper chars
43
     */
44
    protected function generateMergeTags()
45
    {
46
        $mergeTags = $this->generateMergeTagsTrait();
0 ignored issues
show
Bug introduced by
The method generateMergeTagsTrait() does not exist on Nip\MailModule\Models\Em...gs\MergeTagsRecordTrait. Did you maybe mean generateMergeTags()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
47
        $mergeTags = array_map(
48
            function ($item) {
49
                return is_string($item) ? html_entity_decode($item, ENT_QUOTES) : $item;
50
            },
51
            $mergeTags
52
        );
53
54
        return $mergeTags;
55
    }
56
}
57