Completed
Push — master ( 633f87...d85777 )
by Cheren
03:16
created

MaterializeCssTrait::_prepareTooltip()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 4
Ratio 23.53 %

Importance

Changes 0
Metric Value
dl 4
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 3
1
<?php
2
/**
3
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package     Core
10
 * @license     MIT
11
 * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link        https://github.com/CakeCMS/Core".
13
 * @author      Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\View\Helper\Traits;
17
18
use JBZoo\Utils\Arr;
19
use JBZoo\Utils\Str;
20
use Cake\View\Helper;
21
use Cake\Utility\Hash;
22
23
/**
24
 * Trait MaterializeCssTrait
25
 *
26
 * @package Core\View\Helper\Traits
27
 */
28
trait MaterializeCssTrait
29
{
30
31
    /**
32
     * Setup tooltip data-tooltip attr.
33
     *
34
     * @param array $options
35
     * @param string $tooltip
36
     * @return array
37
     */
38
    protected function _dataTooltip(array $options, $tooltip)
39
    {
40
        if (Arr::key('title', $options)) {
41
            $options['data-tooltip'] = $options['title'];
42
        }
43
44
        if (is_string($tooltip)) {
45
            $options['data-tooltip'] = $tooltip;
46
        }
47
48
        return $options;
49
    }
50
51
    /**
52
     * Prepare form buttons.
53
     *
54
     * @param   Helper $helper
55
     * @param   array $options
56
     * @param   string $button
57
     * @return  array
58
     */
59
    protected function _prepareBtn(Helper $helper, array $options, $button)
60
    {
61
        $options = $helper->addClass($options, 'waves-effect waves-light btn');
62
        if (!empty($button)) {
63
            $options = $helper->addClass($options, Str::trim((string) $button));
64
        }
65
66
        return $options;
67
    }
68
69
    /**
70
     * Prepare tooltip attrs.
71
     *
72
     * @param Helper $helper
73
     * @param array $options
74
     * @param string $tooltip
75
     * @return array
76
     */
77
    protected function _prepareTooltip(Helper $helper, array $options, $tooltip)
78
    {
79
        $_options = [
80
            'data-position' => 'top'
81
        ];
82
83 View Code Duplication
        if (Arr::key('tooltipPos', $options)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
            $_options['data-position'] = (string) $options['tooltipPos'];
85
            unset($options['tooltipPos']);
86
        }
87
88
        $options = $this->_tooltipTitle($options, $tooltip);
89
        $options = $this->_dataTooltip($options, $tooltip);
90
        $options = $helper->addClass($options, 'hasTooltip');
91
92
        return Hash::merge($_options, $options);
93
    }
94
95
    /**
96
     * Setup tooltip title.
97
     *
98
     * @param array $options
99
     * @param string $tooltip
100
     * @return array
101
     */
102 View Code Duplication
    protected function _tooltipTitle(array $options, $tooltip)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        if ($tooltip === true && !Arr::key('title', $options)) {
105
            $options['title'] = strip_tags($options['label']);
106
        }
107
108
        if (is_string($tooltip)) {
109
            $options['title'] = $tooltip;
110
        }
111
112
        return $options;
113
    }
114
}
115