Passed
Push — 5.0.0 ( 9fcb89...47cf5a )
by Fèvre
05:30
created

Password::modelName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Xetaravel\View\Components;
4
5
use Closure;
6
use Exception;
7
use Illuminate\Contracts\View\View;
8
use Illuminate\View\Component;
9
10
class Password extends Component
11
{
12
    public string $uuid;
13
14
    public function __construct(
15
        public ?string $label = null,
16
        public ?string $icon = null,
17
        public ?string $iconRight = null,
18
        public ?string $hint = null,
19
        public ?string $hintClass = 'fieldset-label',
20
        public ?string $prefix = null,
21
        public ?string $suffix = null,
22
        public ?bool $inline = false,
23
        public ?bool $clearable = false,
24
25
        // Password
26
        public ?string $passwordIcon = 'heroicon-o-eye-slash',
27
        public ?string $passwordVisibleIcon = 'heroicon-o-eye',
28
        public ?bool $right = false,
29
        public ?bool $onlyPassword = false,
30
31
        // Slots
32
        public mixed $prepend = null,
33
        public mixed $append = null,
34
35
        // Validations
36
        public ?string $errorField = null,
37
        public ?string $errorClass = 'text-error',
38
        public ?bool $omitError = false,
39
        public ?bool $firstErrorOnly = false,
40
    ) {
41
        $this->uuid = md5(serialize($this));
42
43
        // Cannot use a left icon when password toggle should be shown on the left side.
44
        if (($this->icon && ! $this->right) && ! $this->onlyPassword) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->onlyPassword of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
Bug Best Practice introduced by
The expression $this->right of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
45
            throw new Exception("Cannot use `icon` without providing `right` or `onlyPassword`.");
46
        }
47
48
        // Cannot use a right icon when password toggle should be shown on the right side.
49
        if (($this->iconRight && $this->right) && ! $this->onlyPassword) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->onlyPassword of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
50
            throw new Exception("Cannot use `iconRight` when providing `right` and not providing `onlyPassword`.");
51
        }
52
    }
53
54
    public function modelName(): ?string
55
    {
56
        return $this->attributes->whereStartsWith('wire:model')->first();
57
    }
58
59
    public function errorFieldName(): ?string
60
    {
61
        return $this->errorField ?? $this->modelName();
62
    }
63
64
    public function placeToggleLeft(): bool
65
    {
66
        return (! $this->icon && ! $this->right) && ! $this->onlyPassword;
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->onlyPassword of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
Bug Best Practice introduced by
The expression $this->right of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
67
    }
68
69
    public function placeToggleRight(): bool
70
    {
71
        return (! $this->iconRight && $this->right) && ! $this->onlyPassword;
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->onlyPassword of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
72
    }
73
74
    /**
75
     * Get the view / contents that represent the component.
76
     */
77
    public function render(): View|Closure|string
78
    {
79
        return view('components.password');
80
    }
81
}
82