Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added better stubs for DateTimeImmutable, highlighting how the constructor is **NOT** immutable #8350

Merged
merged 22 commits into from Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b4b2bc6
Added better stubs for `DateTimeImmutable`, highlighting how the cons…
Ocramius Jul 31, 2022
dcaf610
Removed `@psalm-immutable` marked from `MyDate` extending `DateTimeIm…
Ocramius Jul 31, 2022
c205d65
`DateTimeImmutable#sub()` always returns another `static` instance, n…
Ocramius Jul 31, 2022
68978b9
s/psalm-pure/psalm-mutation-free, since psalm-mutation-free is safer …
Ocramius Aug 1, 2022
dc7d26a
Removed `DateTimeImmutable::__construct` from the CallMap: fully cove…
Ocramius Aug 5, 2022
267d760
Removed `DateTimeImmutable::sub()` from the CallMap: fully covered by…
Ocramius Aug 5, 2022
58ca4e0
Removed `DateTimeImmutable::createFromFormat()` from the CallMap: ful…
Ocramius Aug 5, 2022
7ee12c7
Removed `DateTimeImmutable::format()` from the CallMap: fully covered…
Ocramius Aug 5, 2022
2b6fddf
Removed `DateTimeImmutable::getTimezone()` from the CallMap: fully co…
Ocramius Aug 5, 2022
1be04e0
Removed `DateTimeImmutable::getOffset()` from the CallMap: fully cove…
Ocramius Aug 5, 2022
002585b
Removed `DateTimeImmutable::getTimestamp()` from the CallMap: fully c…
Ocramius Aug 5, 2022
18557b8
Removed `DateTimeImmutable::diff()` from the CallMap: fully covered b…
Ocramius Aug 5, 2022
7cd3d49
Removed `DateTimeImmutable::modify()` from the CallMap: fully covered…
Ocramius Aug 5, 2022
cb9939c
Removed `DateTimeImmutable::add()` from the CallMap: fully covered by…
Ocramius Aug 5, 2022
4fe554d
Removed `DateTimeImmutable::setTimezone()` from the CallMap: fully co…
Ocramius Aug 5, 2022
e61c593
Removed `DateTimeImmutable::setTime()` from the CallMap: fully covere…
Ocramius Aug 5, 2022
0a6c9d0
Removed `DateTimeImmutable::setDate()` from the CallMap: fully covere…
Ocramius Aug 5, 2022
964f64a
Removed `DateTimeImmutable::setISODate()` from the CallMap: fully cov…
Ocramius Aug 5, 2022
aaac9cc
Removed `DateTimeImmutable::setTimestamp()` from the CallMap: fully c…
Ocramius Aug 5, 2022
a1ed84f
Removed `DateTimeImmutable::createFromMutable()` from the CallMap: fu…
Ocramius Aug 5, 2022
68ffae0
Simplified `DateTimeImmutable::format()`: always returns a `string`
Ocramius Aug 5, 2022
1382877
Removed `DateTimeImmutable::createFromInterface()` from stubs
Ocramius Aug 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
101 changes: 98 additions & 3 deletions stubs/CoreImmutableClasses.phpstub
@@ -1,11 +1,106 @@
<?php

/**
* @psalm-immutable
*/
class DateTimeImmutable implements DateTimeInterface
{
public function __construct(string $datetime = "now", DateTimeZone $timezone = null) {}

/**
* @psalm-pure
Ocramius marked this conversation as resolved.
Show resolved Hide resolved
* @return static|false
*/
public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) {}

/**
* @psalm-pure
* @param string $format
* @return string
*/
public function format($format) {}

/**
* @psalm-pure
* @return DateTimeZone
*/
public function getTimezone() {}

/**
* @psalm-pure
* @return int
*/
public function getOffset() {}

/**
* @psalm-pure
* @return int
*/
public function getTimestamp() {}

/**
* @psalm-pure
* @param bool $absolute
* @return DateInterval
*/
public function diff(DateTimeInterface $targetObject, $absolute = false) {}

/**
* @psalm-pure
* @return static
*/
public function modify(string $modifier) {}

/**
* @psalm-pure
* @return static
*/
public function add(DateInterval $interval) {}

/**
* @psalm-pure
* @return static
*/
public function sub(DateInterval $interval) {}

/**
* @psalm-pure
* @return static|false
*/
public function setTimezone(DateTimeZone $timezone) {}

/**
* @psalm-pure
* @return static|false
*/
public function setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0) {}

/**
* @psalm-pure
* @return static|false
*/
public function setDate(int $year, int $month, int $day) {}

/**
* @psalm-pure
* @return static|false
*/
public function setISODate(int $year, int $week, int $dayOfWeek = 1) {}

/**
* @psalm-pure
* @return static|false
*/
public function setTimestamp(int $unixtimestamp) {}

/**
* @psalm-pure
* @return static
*/
public static function createFromMutable(DateTime $object) {}

/**
* @psalm-pure
* @return self
*/
public static function createFromInterface(DateTimeInterface $object) {}
Ocramius marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/MethodCallTest.php
Expand Up @@ -264,15 +264,14 @@ public static function main(): void {
],
'dateTimeImmutableStatic' => [
'<?php
/** @psalm-immutable */
final class MyDate extends DateTimeImmutable {}

$today = new MyDate();
$yesterday = $today->sub(new DateInterval("P1D"));

$b = (new DateTimeImmutable())->modify("+3 hours");',
'assertions' => [
'$yesterday' => 'MyDate|false',
'$yesterday' => 'MyDate',
Ocramius marked this conversation as resolved.
Show resolved Hide resolved
'$b' => 'DateTimeImmutable',
],
],
Expand Down