Skip to content

Commit

Permalink
fix: Use \DateTimeInterface to check object types instead of `\Date…
Browse files Browse the repository at this point in the history
…Time`
  • Loading branch information
ambroisemaupate committed Mar 20, 2024
1 parent 1d30cef commit 9389865
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getResult(

foreach ($paginator as $result) {
$dateTimeField = reset($result);
if ($dateTimeField instanceof \DateTime) {
if ($dateTimeField instanceof \DateTimeInterface) {
$year = $dateTimeField->format('Y');
$month = $dateTimeField->format('Y-m');

Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/Console/NodesDetailsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (is_array($data)) {
$data = implode(', ', $data);
}
if ($data instanceof \DateTime) {
if ($data instanceof \DateTimeInterface) {
$data = $data->format('c');
}
if ($data instanceof \stdClass) {
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/CustomForm/CustomFormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected function getDocumentFolderForCustomForm(): ?Folder
*/
private function formValueToString($rawValue): string
{
if ($rawValue instanceof \DateTime) {
if ($rawValue instanceof \DateTimeInterface) {
return $rawValue->format('Y-m-d H:i:s');
} elseif (is_array($rawValue)) {
$values = $rawValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function setValue($value)
return $this;
case AttributeInterface::DATETIME_T:
case AttributeInterface::DATE_T:
if ($value instanceof \DateTime) {
if ($value instanceof \DateTimeInterface) {
$this->value = $value->format('Y-m-d H:i:s');
} else {
$this->value = (string) $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ protected function argFqProcess(array &$args): array
*/
if (isset($args['publishedAt'])) {
$tmp = "published_at_dt:";
if (!is_array($args['publishedAt']) && $args['publishedAt'] instanceof \DateTime) {
if (!is_array($args['publishedAt']) && $args['publishedAt'] instanceof \DateTimeInterface) {
$tmp .= $this->formatDateTimeToUTC($args['publishedAt']);
} elseif (
isset($args['publishedAt'][0]) &&
$args['publishedAt'][0] === "BETWEEN" &&
isset($args['publishedAt'][1]) &&
$args['publishedAt'][1] instanceof \DateTime &&
$args['publishedAt'][1] instanceof \DateTimeInterface &&
isset($args['publishedAt'][2]) &&
$args['publishedAt'][2] instanceof \DateTime
$args['publishedAt'][2] instanceof \DateTimeInterface
) {
$tmp .= "[" .
$this->formatDateTimeToUTC($args['publishedAt'][1]) .
Expand All @@ -186,14 +186,14 @@ protected function argFqProcess(array &$args): array
isset($args['publishedAt'][0]) &&
$args['publishedAt'][0] === "<=" &&
isset($args['publishedAt'][1]) &&
$args['publishedAt'][1] instanceof \DateTime
$args['publishedAt'][1] instanceof \DateTimeInterface
) {
$tmp .= "[* TO " . $this->formatDateTimeToUTC($args['publishedAt'][1]) . "]";
} elseif (
isset($args['publishedAt'][0]) &&
$args['publishedAt'][0] === ">=" &&
isset($args['publishedAt'][1]) &&
$args['publishedAt'][1] instanceof \DateTime
$args['publishedAt'][1] instanceof \DateTimeInterface
) {
$tmp .= "[" . $this->formatDateTimeToUTC($args['publishedAt'][1]) . " TO *]";
}
Expand Down
2 changes: 1 addition & 1 deletion lib/RoadizCoreBundle/src/Xlsx/XlsxExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function exportXlsx($data, $keys = [])
continue;
}

if ($value instanceof \DateTime) {
if ($value instanceof \DateTimeInterface) {
$value = Date::PHPToExcel($value);
$activeSheet->getStyle($columnAlpha . ($activeRow))
->getNumberFormat()
Expand Down

0 comments on commit 9389865

Please sign in to comment.