Completed
Pull Request — master (#16)
by Sergii
05:09
created

DatePicker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 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
// Helpers.
10
use Behat\DebugExtension\Debugger;
11
12
class DatePicker implements DatePickerInterface
13
{
14
    use Debugger;
15
16
    /**
17
     * @var DatePickerInterface
18
     */
19
    private $datePicker;
20
21
    /**
22
     * {@inheritdoc}
23
     *
24
     * @see DatePickerBase::__construct()
25
     */
26
    public function __construct(RawTqContext $context, $selector, $date)
27
    {
28
        $session = $context->getSession();
29
30
        if (empty($session->evaluateScript('jQuery.fn.datepicker'))) {
31
            throw new \RuntimeException('jQuery DatePicker is not available on the page.');
32
        }
33
34
        // Drupal 8 will use native "date" field if available.
35
        $class = $session->evaluateScript('Modernizr && Modernizr.inputtypes.date') ? Native::class : JQuery::class;
36
37
        self::debug(['The "%s" date picker will be used.'], [$class]);
38
39
        $this->datePicker = new $class($context, $session, $context->element('*', $selector), $date);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function setDate()
46
    {
47
        return $this->datePicker->{__FUNCTION__}();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function isDateSelected()
54
    {
55
        return $this->datePicker->{__FUNCTION__}();
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function isDateAvailable()
62
    {
63
        return $this->datePicker->{__FUNCTION__}();
64
    }
65
}
66