Skip to content

Commit

Permalink
Merge pull request #362 from thecodingmachine/date
Browse files Browse the repository at this point in the history
FIX: regenerated the files without losing support for date
  • Loading branch information
Kharhamel authored Jun 9, 2022
2 parents 5570fbf + 1b743c5 commit 5bbf02a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
25 changes: 22 additions & 3 deletions generated/datetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ function date_parse_from_format(string $format, string $datetime): ?array


/**
*
* date_parse parses the given
* datetime string according to the same rules as
* strtotime and
* DateTimeImmutable::__construct. Instead of returning a
* Unix timestamp (with strtotime) or a
* DateTimeImmutable object (with
* DateTimeImmutable::__construct, it returns an
* associative array with the information that it could detect in the given
* datetime string.
*
* If no information about a certain group of elements can be found, these
* array elements will be set to FALSE or are missing. If needed for
* constructing a timestamp or DateTimeImmutable object from
* the same datetime string, more fields can be set to
* a non-FALSE value. See the examples for cases where that happens.
*
* @param string $datetime Date/time in format accepted by
* DateTimeImmutable::__construct.
Expand Down Expand Up @@ -359,10 +373,15 @@ function date_sunset(int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING, fl

/**
* Returns a string formatted according to the given format string using the
* given integer timestamp or the current time
* if no timestamp is given. In other words, timestamp
* given integer timestamp (Unix timestamp) or the current time
* if no timestamp is given. In other words, timestamp
* is optional and defaults to the value of time.
*
* Unix timestamps do not handle timezones. Use the
* DateTimeImmutable class, and its
* DateTimeInterface::format formatting method to
* format date/time information with a timezone attached.
*
* @param string $format Format accepted by DateTimeInterface::format.
* @param int $timestamp The optional timestamp parameter is an
* int Unix timestamp that defaults to the current
Expand Down
4 changes: 2 additions & 2 deletions generated/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ function fflush($stream): void
* @param string $enclosure The optional enclosure parameter sets the field enclosure character (one single-byte character only).
* @param string $escape The optional escape parameter sets the escape character (at most one single-byte character).
* An empty string ("") disables the proprietary escape mechanism.
* @return array|false|null Returns an indexed array containing the fields read on success.
* @return array|null Returns an indexed array containing the fields read on success.
* @throws FilesystemException
*
*/
function fgetcsv($stream, int $length = null, string $separator = ",", string $enclosure = "\"", string $escape = "\\")
function fgetcsv($stream, int $length = null, string $separator = ",", string $enclosure = "\"", string $escape = "\\"): ?array
{
error_clear_last();
if ($escape !== "\\") {
Expand Down
2 changes: 1 addition & 1 deletion generated/openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function openssl_csr_sign($csr, $ca_certificate, $private_key, int $days, array
* OPENSSL_ZERO_PADDING.
* @param string $iv A non-NULL Initialization Vector.
* @param string $tag The authentication tag in AEAD cipher mode. If it is incorrect, the authentication fails and the function returns FALSE.
* @param string $aad Additional authentication data.
* @param string $aad Additional authenticated data.
* @return string The decrypted string on success.
* @throws OpensslException
*
Expand Down
2 changes: 1 addition & 1 deletion generator/config/CustomPhpStanFunctionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'curl_share_errno' => ['int', 'share_handle' => 'CurlShareHandle'],
'curl_share_setopt' => ['void', 'share_handle' => 'CurlShareHandle', 'option' => 'int', 'value' => 'mixed'],
'curl_unescape' => ['string', 'handle' => 'CurlHandle', 'string' => 'string'],

'fgetcsv' => ['array|false|null', 'fp'=>'resource', 'length='=>'0|positive-int', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'], //phpstan default return type is too hard to analyse
//todo: edit the reader to turn 0|1 into int
'preg_match' => ['int|false', 'pattern'=>'string', 'subject'=>'string', '&w_subpatterns='=>'string[]', 'flags='=>'int', 'offset='=>'int'], //int|false instead of 0|1|false
];
2 changes: 1 addition & 1 deletion generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function detectFalsyFunction(): bool
return true;
}
//used for date
if (preg_match('/If a non-numeric value is used for
if (preg_match('/If a non-numeric value is used for
\<parameter\>timestamp\<\/parameter\>, &false; is returned/m', $returnValuesSection)) {
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions generator/tests/PhpStanFunctions/PhpStanTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ public function testErrorTypeInteraction(): void
$param = new PhpStanType('int|null');
$this->assertEquals('int', $param->getDocBlockType(Method::NULLSY_TYPE));
$this->assertEquals('int', $param->getSignatureType(Method::NULLSY_TYPE));

$param = new PhpStanType('array|false|null');
$this->assertEquals('array|null', $param->getDocBlockType(Method::FALSY_TYPE));
$this->assertEquals('?array', $param->getSignatureType(Method::FALSY_TYPE));
}

public function testDuplicateType(): void
Expand Down

0 comments on commit 5bbf02a

Please sign in to comment.