Password   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 69
rs 10
wmc 16

6 Methods

Rating   Name   Duplication   Size   Complexity  
A errorFieldName() 0 3 1
B __construct() 0 36 7
A placeToggleLeft() 0 3 3
A modelName() 0 3 1
A placeToggleRight() 0 3 3
A render() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\View\Components;
6
7
use Closure;
8
use Exception;
9
use Illuminate\Contracts\View\View;
10
use Illuminate\View\Component;
11
12
class Password extends Component
13
{
14
    public string $uuid;
15
16
    public function __construct(
17
        public ?string $label = null,
18
        public ?string $icon = null,
19
        public ?string $iconRight = null,
20
        public ?string $hint = null,
21
        public ?string $hintClass = 'fieldset-label',
22
        public ?string $prefix = null,
23
        public ?string $suffix = null,
24
        public ?bool $inline = false,
25
        public ?bool $clearable = false,
26
27
        // Password
28
        public ?string $passwordIcon = 'heroicon-o-eye-slash',
29
        public ?string $passwordVisibleIcon = 'heroicon-o-eye',
30
        public ?bool $right = false,
31
        public ?bool $onlyPassword = false,
32
33
        // Slots
34
        public mixed $prepend = null,
35
        public mixed $append = null,
36
37
        // Validations
38
        public ?string $errorClass = 'text-error',
39
        public ?bool $omitError = false,
40
        public ?bool $firstErrorOnly = false,
41
    ) {
42
        $this->uuid = md5(serialize($this));
43
44
        // Cannot use a left icon when password toggle should be shown on the left side.
45
        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...
46
            throw new Exception("Cannot use `icon` without providing `right` or `onlyPassword`.");
47
        }
48
49
        // Cannot use a right icon when password toggle should be shown on the right side.
50
        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...
51
            throw new Exception("Cannot use `iconRight` when providing `right` and not providing `onlyPassword`.");
52
        }
53
    }
54
55
    public function modelName(): ?string
56
    {
57
        return $this->attributes->whereStartsWith('wire:model')->first();
58
    }
59
60
    public function errorFieldName(): ?string
61
    {
62
        return $this->modelName() ?? $this->attributes->whereStartsWith('name')->first();
63
    }
64
65
    public function placeToggleLeft(): bool
66
    {
67
        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...
68
    }
69
70
    public function placeToggleRight(): bool
71
    {
72
        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...
73
    }
74
75
    /**
76
     * Get the view / contents that represent the component.
77
     */
78
    public function render(): View|Closure|string
79
    {
80
        return view('components.password');
81
    }
82
}
83