PassesModes::formatModes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Slides\Connector\Auth\Concerns;
4
5
/**
6
 * Trait PassesModes
7
 *
8
 * @package Slides\Connector\Auth\Concerns
9
 */
10
trait PassesModes
11
{
12
    /**
13
     * The passed modes.
14
     *
15
     * @var array
16
     */
17
    private $modes;
18
19
    /**
20
     * Parse and retrieve the modes.
21
     *
22
     * @return array
23
     */
24
    protected function modes(): array
25
    {
26
        $modes = [
27
            'passwords' => $this->option('passwords'),
0 ignored issues
show
Bug introduced by
It seems like option() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

27
            'passwords' => $this->/** @scrutinizer ignore-call */ option('passwords'),
Loading history...
28
            'users' => $this->option('users'),
29
        ];
30
31
        return $this->modes = array_filter($modes);
32
    }
33
34
    /**
35
     * Checks whether user has a mode.
36
     *
37
     * @param string $mode
38
     *
39
     * @return bool
40
     */
41
    protected function hasMode(string $mode): bool
42
    {
43
        return array_key_exists($mode, $this->modes());
44
    }
45
46
    /**
47
     * Checks whether any mode is passed.
48
     *
49
     * @return bool
50
     */
51
    protected function hasModes(): bool
52
    {
53
        return count($this->modes()) > 0;
54
    }
55
56
    /**
57
     * Write modes to the output.
58
     *
59
     * @param array $modes
60
     *
61
     * @return void
62
     */
63
    protected function displayModes(array $modes = null)
64
    {
65
        $modes = $this->formatModes($modes ?? $this->modes());
66
67
        if($modes) {
68
            $this->output->block('Passed modes: ' . $modes, null, 'comment');
69
        }
70
    }
71
72
    /**
73
     * Format the modes to a string.
74
     *
75
     * @param array $modes
76
     *
77
     * @return string
78
     */
79
    protected function formatModes(array $modes): string
80
    {
81
        return implode(', ', array_keys($modes));
82
    }
83
}