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

Fix PHPStan #1938

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Propel/Common/Config/Loader/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ private function resolveString(string $value, array $resolving = [])
* when it matches the entire $value, it can resolve to any value.
* otherwise, it is replaced with the resolved string or number.
*/
/** @phpstan-var string|null $onlyKey */
$onlyKey = null;
$replaced = preg_replace_callback('/%([^%\s]*+)%/', function ($match) use ($resolving, $value, &$onlyKey) {
$key = $match[1];
Expand Down
10 changes: 8 additions & 2 deletions src/Propel/Runtime/Util/PropelDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use DateTimeInterface;
use DateTimeZone;
use Exception;
use InvalidArgumentException;
use Propel\Runtime\Exception\PropelException;

/**
Expand Down Expand Up @@ -68,13 +69,18 @@ protected static function isTimestamp($value): bool
*
* Usually `new \Datetime()` does not contain milliseconds so you need a method like this.
*
* @param bool|null $time optional in seconds. floating point allowed.
* @param string|null $time Optional, in seconds. Floating point allowed.
*
* @throws \InvalidArgumentException
*
* @return \DateTime
*/
public static function createHighPrecision(?bool $time = null): DateTime
public static function createHighPrecision(?string $time = null): DateTime
{
$dateTime = DateTime::createFromFormat('U.u', $time ?: self::getMicrotime());
if ($dateTime === false) {
throw new InvalidArgumentException('Cannot create a datetime object from `' . $time . '`');
}

$dateTime->setTimeZone(new DateTimeZone(date_default_timezone_get()));

Expand Down
8 changes: 4 additions & 4 deletions src/Propel/Runtime/Util/UuidConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
namespace Propel\Runtime\Util;

/**
* Helpes to manually convert uuids to byte types
* Helps to manually convert UUIDs to byte types
*/
class UuidConverter
{
/**
* Transforms a uuid string to a binary string.
* Transforms a UUID string to a binary string.
*
* @param string $uuid
* @param bool $swapFlag Swap first four bytes for better indexing of version-1 UUIDs (@link https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin)
Expand All @@ -31,11 +31,11 @@ public static function uuidToBin(string $uuid, bool $swapFlag = true): string
$uuid,
);

return hex2bin($rawHex);
return (string)hex2bin($rawHex);
}

/**
* Transforms a binary string to a uuid string.
* Transforms a binary string to a UUID string.
*
* @param string $bin
* @param bool $swapFlag Assume bytes were swapped (@link https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_bin-to-uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function validate($value, Constraint $constraint): void
$object = $this->context->getObject();
if ($object->isNew() && $matches->count() > 0) {
$this->context->addViolation($constraint->message);
} elseif ($object->isModified() && $matches->count() > (in_array($columnName, $object->getModifiedColumns()) ? 0 : 1)) {
} elseif ($object->isModified() && $matches->count() > (in_array($columnName, $object->getModifiedColumns(), true) ? 0 : 1)) {
$this->context->addViolation($constraint->message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Propel/Tests/Runtime/Util/PropelDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public function testCreateHighPrecisioniTz()
$originalTimezone = date_default_timezone_get();
date_default_timezone_set('America/New_York');

$createHP = PropelDateTime::createHighPrecision();
$createHP = PropelDateTime::createHighPrecision(PropelDateTime::getMicrotime());

$dt = new DateTime();
$dt->setTimezone(new DateTimeZone('America/New_York'));
Expand Down