for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Sergii Bondarenko, <[email protected]>
*/
namespace Drupal\TqExtension\Utils\DatePicker;
class Native extends DatePickerBase
{
* @var string
private $format = '';
private $time = '';
private $formatted = '';
* {@inheritdoc}
public function initialize()
$this->format = $this->jQuery("data('drupalDateFormat')");
if (empty($this->format)) {
throw new \RuntimeException('Unknown date format.');
}
$this->time = strtotime($this->date);
$time
string
strtotime($this->date)
integer
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.
$answer = 42; $correct = false; $correct = (bool) $answer;
$this->formatted = date($this->format, $this->time);
public function isDateAvailable()
$ranges = [];
foreach (['min', 'max'] as $range) {
$value = $this->element->getAttribute($range);
// If no range was set then use the original date as its value.
$ranges[$range] = null === $value ? $this->time : strtotime($value);
if ($this->time < $ranges['min'] || $this->time > $ranges['max']) {
throw new \Exception(sprintf('The "%s" is not available for choosing.', $this->date));
return $this;
public function setDate()
$this->jQuery("val('$this->formatted')");
public function isDateSelected()
$value = $this->jQuery('val()');
self::debug(['Comparing "%s" with "%s".'], [$value, $this->formatted]);
if ($value !== $this->formatted) {
throw new \Exception(sprintf('DatePicker contains the "%s" but should "%s".', $value, $this->formatted));
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.