CanMakePassword   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
c 1
b 0
f 0
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setText() 0 4 1
A make() 0 6 1
A text() 0 3 1
1
<?php
2
3
namespace Benjafield\LaravelPasswordManager\Traits;
4
5
trait CanMakePassword
6
{
7
    /**
8
     * The plain text version of the password.
9
     *
10
     * @var string
11
     */
12
    protected string $text;
13
14
    /**
15
     * Create a new instance of a password model.
16
     *
17
     * @param string $name
18
     * @param string $dynamic
19
     * @param string $password
20
     * @param string|null $text
21
     * @return self
22
     */
23
    public static function make(string $name, string $dynamic, string $password, string $text = null): self
24
    {
25
        $attributes = compact('name', 'dynamic', 'password');
26
27
        return (new self($attributes))
0 ignored issues
show
Unused Code introduced by
The call to Benjafield\LaravelPasswo...Password::__construct() has too many arguments starting with $attributes. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        return (/** @scrutinizer ignore-call */ new self($attributes))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
28
            ->setText($text);
0 ignored issues
show
Bug introduced by
It seems like $text can also be of type null; however, parameter $value of Benjafield\LaravelPasswo...MakePassword::setText() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
            ->setText(/** @scrutinizer ignore-type */ $text);
Loading history...
29
    }
30
31
    /**
32
     * Set the plain text version of the password.
33
     * Not included when serialized.
34
     *
35
     * @param string $value
36
     * @return $this
37
     */
38
    public function setText(string $value): self
39
    {
40
        $this->text = $value;
41
        return $this;
42
    }
43
44
    /**
45
     * Retrieve the plain text version of the password.
46
     *
47
     * @return string|null
48
     */
49
    public function text(): string|null
50
    {
51
        return $this->text;
52
    }
53
}