Completed
Pull Request — master (#16)
by Sergii
04:07
created

DatePicker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A setDate() 0 4 1
A isDateSelected() 0 4 1
A isDateAvailable() 0 4 1
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Drupal\TqExtension\Utils\DatePicker;
6
7
// Contexts.
8
use Drupal\TqExtension\Context\RawTqContext;
9
10
final class DatePicker extends DatePickerBase
11
{
12
    /**
13
     * @var DatePickerBase
14
     */
15
    private $datePicker;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function __construct(RawTqContext $context, $selector, $date)
21
    {
22
        parent::__construct($context, $selector, $date);
23
24
        if (null === $this->execute('jQuery.fn.datepicker')) {
25
            throw new \RuntimeException('jQuery DatePicker is not available on the page.');
26
        }
27
28
        // Drupal 8 will use native "date" field if available.
29
        $class = $this->execute('Modernizr && Modernizr.inputtypes.date') ? Native::class : JQuery::class;
30
        $this->datePicker = new $class($context, $selector, $date);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function setDate()
37
    {
38
        return $this->datePicker->{__FUNCTION__}();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function isDateSelected()
45
    {
46
        return $this->datePicker->{__FUNCTION__}();
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function isDateAvailable()
53
    {
54
        return $this->datePicker->{__FUNCTION__}();
55
    }
56
}
57