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

DatePicker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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