GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

HasTextAttributes::append()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Menu\Traits;
4
5
trait HasTextAttributes
6
{
7
    /**
8
     * Prepend the anchor with a string of html on render.
9
     *
10
     * @param string $prepend
11
     *
12
     * @return $this
13
     */
14
    public function prepend(string $prepend)
15
    {
16
        $this->prepend = $prepend;
0 ignored issues
show
Bug introduced by
The property prepend does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
18
        return $this;
19
    }
20
21
    /**
22
     * Prepend the text with a string of html on render if a certain condition is
23
     * met.
24
     *
25
     * @param bool $condition
26
     * @param string $prepend
27
     *
28
     * @return $this
29
     */
30
    public function prependIf($condition, string $prepend)
31
    {
32
        if ($this->resolveCondition($condition)) {
0 ignored issues
show
Bug introduced by
It seems like resolveCondition() 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...
33
            return $this->prepend($prepend);
34
        }
35
36
        return $this;
37
    }
38
39
    /**
40
     * Append a text of html to the menu on render.
41
     *
42
     * @param string $append
43
     *
44
     * @return $this
45
     */
46
    public function append(string $append)
47
    {
48
        $this->append = $append;
0 ignored issues
show
Bug introduced by
The property append does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
49
50
        return $this;
51
    }
52
53
    /**
54
     * Append the text with a string of html on render if a certain condition is
55
     * met.
56
     *
57
     * @param bool $condition
58
     * @param string $append
59
     *
60
     * @return static
61
     */
62
    public function appendIf($condition, string $append)
63
    {
64
        if ($this->resolveCondition($condition)) {
0 ignored issues
show
Bug introduced by
It seems like resolveCondition() 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...
65
            return $this->append($append);
66
        }
67
68
        return $this;
69
    }
70
}
71