-
-
Notifications
You must be signed in to change notification settings - Fork 54
Add Range types #372
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
base: main
Are you sure you want to change the base?
Add Range types #372
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
declare(strict_types=1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace MartinGeorgiev\Doctrine\DBAL\Types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use Doctrine\DBAL\Types\Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use MartinGeorgiev\Model\ArithmeticRange; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Implementation of PostgreSQL NUMRANGE data type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @see https://www.postgresql.org/docs/current/rangetypes.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @since 3.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @author Jan Klan <jan@klan.com.au> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class NumRange extends BaseType | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
protected const TYPE_NAME = 'numrange'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function convertToPHPValue($value, AbstractPlatform $platform): ?ArithmeticRange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (null === $value || 'empty' === $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!\is_string($value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new \RuntimeException('NumRange expects only string. Unexpected value from DB: '.$value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failure on line 30 in src/MartinGeorgiev/Doctrine/DBAL/Types/NumRange.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!\preg_match('/(\[|\()(.*)\,(.*)(\]|\))/', $value, $matches)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new \RuntimeException('unexpected value from DB: '.$value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return ArithmeticRange::createFromString($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (empty($value)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$stringValue = (string) $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failure on line 46 in src/MartinGeorgiev/Doctrine/DBAL/Types/NumRange.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if ('(,)' === $stringValue) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $stringValue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+40
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix mixed type handling in string conversion The static analysis tools are reporting an error on line 46 when casting public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
{
if (empty($value)) {
return null;
}
- $stringValue = (string) $value;
+ $stringValue = \is_object($value) && method_exists($value, '__toString')
+ ? (string) $value
+ : (\is_scalar($value) ? (string) $value : '');
if ('(,)' === $stringValue) {
return null;
}
return $stringValue;
} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 46-46: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 46-46: 🤖 Prompt for AI Agents (early access)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,74 @@ | ||||||||||||||||||||||||||||||||||||
<?php | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
declare(strict_types=0); | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix strict types declaration. The strict_types declaration should be set to 1, not 0, to prevent type coercion and ensure consistent type checking. -declare(strict_types=0);
+declare(strict_types=1); 🤖 Prompt for AI Agents (early access)
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
namespace MartinGeorgiev\Model; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
use MartinGeorgiev\Utils\MathUtils; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||
* @implements RangeInterface<float|int> | ||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||
class ArithmeticRange extends BaseRange | ||||||||||||||||||||||||||||||||||||
Check failure on line 12 in src/MartinGeorgiev/Model/ArithmeticRange.php
|
||||||||||||||||||||||||||||||||||||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix class annotation and implementation. While the /**
- * @implements RangeInterface<float|int>
+ * @extends BaseRange<float|int>
*/
class ArithmeticRange extends BaseRange 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 12-12: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 12-12: 🤖 Prompt for AI Agents (early access)
|
||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
public function __construct( | ||||||||||||||||||||||||||||||||||||
public null|float|int $lower, | ||||||||||||||||||||||||||||||||||||
public null|float|int $upper, | ||||||||||||||||||||||||||||||||||||
public bool $lowerInclusive = true, | ||||||||||||||||||||||||||||||||||||
public bool $upperInclusive = false, | ||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||
// Void | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public function __toString(): string | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
if (null !== $this->lower && $this->lower === $this->upper && !$this->lowerInclusive && !$this->upperInclusive) { | ||||||||||||||||||||||||||||||||||||
return 'empty'; | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return \sprintf( | ||||||||||||||||||||||||||||||||||||
'%s%s,%s%s', | ||||||||||||||||||||||||||||||||||||
$this->lowerInclusive ? '[' : '(', | ||||||||||||||||||||||||||||||||||||
$this->lower, | ||||||||||||||||||||||||||||||||||||
$this->upper, | ||||||||||||||||||||||||||||||||||||
$this->upperInclusive ? ']' : ')', | ||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
public function contains(mixed $target): bool | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
return MathUtils::inRange($target, $this->lower, $this->upper, $this->lowerInclusive, $this->upperInclusive); | ||||||||||||||||||||||||||||||||||||
Check failure on line 40 in src/MartinGeorgiev/Model/ArithmeticRange.php
|
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
Comment on lines
+38
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Type compatibility issue in contains method. The static analyzer is detecting a potential type compatibility issue when passing values to Consider explicitly casting or validating the input parameter: public function contains(mixed $target): bool
{
- return MathUtils::inRange($target, $this->lower, $this->upper, $this->lowerInclusive, $this->upperInclusive);
+ if (!is_numeric($target)) {
+ return false;
+ }
+ return MathUtils::inRange(
+ is_numeric($target) ? (float)$target : null,
+ $this->lower,
+ $this->upper,
+ $this->lowerInclusive,
+ $this->upperInclusive
+ );
} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 40-40: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 40-40: 🤖 Prompt for AI Agents (early access)
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||
* @see https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-INFINITE | ||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||
public static function createFromString(string $value): self | ||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||
if (!\preg_match('/([\[(])(.*),(.*)([])])/', $value, $matches)) { | ||||||||||||||||||||||||||||||||||||
throw new \RuntimeException('Unexpected value: '.$value); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
$startParenthesis = $matches[1]; | ||||||||||||||||||||||||||||||||||||
$startsAtString = \trim($matches[2], '"'); | ||||||||||||||||||||||||||||||||||||
$endsAtString = \trim($matches[3], '"'); | ||||||||||||||||||||||||||||||||||||
$endParenthesis = $matches[4]; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (\in_array($startsAtString, ['infinity', '-infinity', ''], true)) { | ||||||||||||||||||||||||||||||||||||
$startsAt = null; | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
$startsAt = MathUtils::stringToNumber($startsAtString); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
if (\in_array($endsAtString, ['infinity', '-infinity', ''], true)) { | ||||||||||||||||||||||||||||||||||||
$endsAt = null; | ||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||
$endsAt = MathUtils::stringToNumber($endsAtString); | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
$startInclusive = '[' === $startParenthesis; | ||||||||||||||||||||||||||||||||||||
$endInclusive = ']' === $endParenthesis; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
return new NumRange($startsAt, $endsAt, $startInclusive, $endInclusive); | ||||||||||||||||||||||||||||||||||||
Check failure on line 72 in src/MartinGeorgiev/Model/ArithmeticRange.php
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect class instantiation in createFromString. The method returns - return new NumRange($startsAt, $endsAt, $startInclusive, $endInclusive);
+ return new self($startsAt, $endsAt, $startInclusive, $endInclusive); 🧰 Tools🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 72-72: [failure] 72-72: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 72-72: [failure] 72-72: 🤖 Prompt for AI Agents (early access)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, the class was first called NumRange. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @janklan Thanks for the explanation! That makes sense - the class was renamed from NumRange to ArithmeticRange, but the instantiation wasn't updated. The suggested fix (changing |
||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
declare(strict_types=0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix strict types declaration. The strict_types declaration should be set to 1, not 0, to prevent type coercion and ensure consistent type checking. -declare(strict_types=0);
+declare(strict_types=1); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents (early access)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CS Fixer added non-strict types because the strictness can't be guaranteed. I guess the strictness can be introduced by addressing the underlying reasons (highlighted below by the AI), but the question is, "do we care"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed:
Length of output: 1593 🏁 Script executed:
Length of output: 2637 @janklan I see why CS Fixer added public static function createFromString(string $value): self
{
// ...
return new NumRange($startsAt, $endsAt, $startInclusive, $endInclusive);
} This would throw a type error with strict typing. The rest of your codebase (339 files) uses Do you care? It depends on how much you value type safety and codebase consistency. If you want to fix it, you could either:
What approach would you prefer? 🧬 Code Graph Analysis ResultsRelevant snippets from
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace MartinGeorgiev\Model; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
abstract class BaseRange implements RangeInterface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failure on line 7 in src/MartinGeorgiev/Model/BaseRange.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add generic type parameters to the class definition. The class implements the generic RangeInterface but doesn't specify its type parameter, which is causing static analysis errors across all PHP versions. -abstract class BaseRange implements RangeInterface
+/**
+ * @template T of int|float|\DateTimeInterface
+ * @implements RangeInterface<T>
+ */
+abstract class BaseRange implements RangeInterface 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 7-7: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 7-7: 🤖 Prompt for AI Agents (early access)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO superfluous, but "why not" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @janklan I understand your view! While it might seem superfluous since PHP doesn't enforce generic type parameters at runtime, it helps static analysis tools properly validate type safety and provides better code documentation. Thanks for being open to the improvement - it'll resolve those static analysis errors across all PHP versions. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function isLowerInfinite(): bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null === $this->lower; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failure on line 11 in src/MartinGeorgiev/Model/BaseRange.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define the lower and upper boundary properties or accessor methods. The class accesses undefined properties
Static analysis fails on all PHP and Doctrine versions for this reason. abstract class BaseRange implements RangeInterface
{
+ /**
+ * @var T|null
+ */
+ protected $lower;
+
+ /**
+ * @var T|null
+ */
+ protected $upper;
+
+ /**
+ * @return T|null
+ */
+ protected function getLower()
+ {
+ return $this->lower;
+ }
+
+ /**
+ * @return T|null
+ */
+ protected function getUpper()
+ {
+ return $this->upper;
+ }
public function isLowerInfinite(): bool
{
return null === $this->lower;
} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0[failure] 11-11: 🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1[failure] 11-11: 🤖 Prompt for AI Agents (early access)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @janklan I see your point. You're right that more sophisticated static analysis tools like PHPStan (with appropriate configuration) can understand this inheritance pattern and recognize that child classes define these properties. The issue is that the GitHub checks appear to be using a tool or configuration that analyzes the BaseRange class in isolation, without considering implementations. This explains why all builds are failing with the same error. If you're comfortable with the current approach and PHPStan is fine with it locally, you have a few options:
Ultimately it's your decision based on your team's preferences for explicitness vs. conciseness. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function isUpperInfinite(): bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null === $this->upper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failure on line 16 in src/MartinGeorgiev/Model/BaseRange.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function isEmpty(): bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return null !== $this->lower && $this->lower === $this->upper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failure on line 21 in src/MartinGeorgiev/Model/BaseRange.php
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function isInfinite(): bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $this->isLowerInfinite() && $this->isUpperInfinite(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function hasSingleBoundary(): bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return !$this->isLowerInfinite() xor !$this->isUpperInfinite(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function hasBothBoundaries(): bool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return !$this->isLowerInfinite() && !$this->isUpperInfinite(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Model; | ||
|
||
/** | ||
* @template T of int|float|\DateTimeInterface | ||
*/ | ||
interface RangeInterface extends \Stringable | ||
{ | ||
/** | ||
* @param T $target | ||
*/ | ||
public function contains(mixed $target): bool; | ||
|
||
public function isLowerInfinite(): bool; | ||
|
||
public function isUpperInfinite(): bool; | ||
|
||
public function isEmpty(): bool; | ||
|
||
public function isInfinite(): bool; | ||
|
||
public function hasSingleBoundary(): bool; | ||
|
||
public function hasBothBoundaries(): bool; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MartinGeorgiev\Utils; | ||
|
||
class MathUtils | ||
{ | ||
/** | ||
* Decides whether the provided $value is in a range delimited by $start and $end values. | ||
* | ||
* - If $start is null, then the comparison is "lesser than $end" only | ||
* - If $end is null, the comparison is "greater than $start" only | ||
* - The $(start|end)Inclusive determine whether the comparison is "lesser/greater than", or "lesser/greater or equal than" | ||
*/ | ||
public static function inRange( | ||
null|float|int $value, | ||
null|float|int $start = null, | ||
null|float|int $end = null, | ||
bool $startInclusive = true, | ||
bool $endInclusive = false, | ||
): bool { | ||
if (null === $value) { | ||
return false; | ||
} | ||
|
||
if (null !== $start && null !== $end && (float) $start === (float) $end) { | ||
return (float) $value === (float) $start; | ||
} | ||
|
||
if (null === $start) { | ||
$startInclusive = true; | ||
} | ||
|
||
if (null === $end) { | ||
$endInclusive = true; | ||
} | ||
|
||
// Depending on this->range[Start/End]Inclusive, we will use (>= or >) and (<= or <) to work out where the value is | ||
$isGreater = $startInclusive ? $value >= $start : $value > $start; | ||
$isLesser = $endInclusive ? $value <= $end : $value < $end; | ||
|
||
return | ||
(null === $start || $isGreater) | ||
&& (null === $end || $isLesser); | ||
} | ||
|
||
public static function stringToNumber(?string $number): null|float|int | ||
{ | ||
if (!\is_numeric($number)) { | ||
return null; | ||
} | ||
|
||
return ((float) $number == (int) $number) ? (int) $number : (float) $number; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix mixed type handling to resolve static analysis errors
The static analysis tools are reporting errors in this method. The issue occurs when concatenating
$value
with a string, as$value
is treated as mixed by the analyzer. You should use explicit type casting or checking.📝 Committable suggestion
🧰 Tools
🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🪛 GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
[failure] 30-30:
Binary operation "." between 'NumRange expects…' and mixed results in an error.
🤖 Prompt for AI Agents (early access)