Completed
Push — master ( 4fa96a...ba6212 )
by ARCANEDEV
03:18
created

ActivateLinks::activateModalWithIcon()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 1
nop 4
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Arcanesoft\Core\Helpers\UI\LinkTraits;
2
3
/**
4
 * Trait     ActivateLinks
5
 *
6
 * @package  Arcanesoft\Core\Helpers\UI\LinkTraits
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
trait ActivateLinks
10
{
11
    /**
12
     * Generate activate icon link.
13
     *
14
     * @param  bool    $active
15
     * @param  string  $url
16
     * @param  array   $attributes
17
     * @param  bool    $disabled
18
     *
19
     * @return self
20
     */
21 18
    public static function activateIcon($active, $url, array $attributes = [], $disabled = false)
22
    {
23 18
        return self::make($active ? 'enable' : 'disable', $url, $attributes, $disabled)
24 18
                   ->size('xs')
25 18
                   ->withTitle(false)
26 18
                   ->icon(true);
27
    }
28
29
    /**
30
     * Generate activate icon link for modals (reverse button based on active state).
31
     *
32
     * @param  bool    $active
33
     * @param  string  $url
34
     * @param  array   $attributes
35
     * @param  bool    $disabled
36
     *
37
     * @return self
38
     */
39 3
    public static function activateModalIcon($active, $url, array $attributes = [], $disabled = false)
40
    {
41 3
        $dataAttribute = 'data-current-status';
42
        $statuses      = [
43 3
            'enabled'  => 'enabled',
44 1
            'disabled' => 'disabled',
45 1
        ];
46
47 3
        return static::activateIcon( ! $active, $url, $attributes, $disabled)
0 ignored issues
show
Bug introduced by
It seems like setAttribute() 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...
48 3
                     ->setAttribute($dataAttribute, $statuses[$active ? 'enabled' : 'disabled']);
49
    }
50
51
    /**
52
     * Generate activate link with icon for modals (reverse button based on active state).
53
     *
54
     * @param  bool    $active
55
     * @param  string  $url
56
     * @param  array   $attributes
57
     * @param  bool    $disabled
58
     *
59
     * @return self
60
     */
61 3
    public static function activateModalWithIcon($active, $url, array $attributes = [], $disabled = false)
62
    {
63 3
        $dataAttribute = 'data-current-status';
64
        $statuses      = [
65 3
            'enabled'  => 'enabled',
66 1
            'disabled' => 'disabled',
67 1
        ];
68
69 3
        return static::activateIcon( ! $active, $url, $attributes, $disabled)
0 ignored issues
show
Bug introduced by
It seems like setAttribute() 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...
70 3
                     ->setAttribute($dataAttribute, $statuses[$active ? 'enabled' : 'disabled'])
71 3
                     ->size('sm')
72 3
                     ->withTitle(true)
73 3
                     ->tooltip(false);
74
    }
75
}
76