Skip to content
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"doctrine/mongodb-odm": "^1.3 || ^2.1",
"doctrine/orm": "^2.9.1",
"doctrine/persistence": "^1.1 || ^2.0",
"nesbot/carbon": "^2.49",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/phpstan-phpunit": "^0.12.16",
"phpstan/phpstan-strict-rules": "^0.12.5",
Expand Down
6 changes: 6 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ services:
tags: [phpstan.doctrine.typeDescriptor]

# 3rd party Type descriptors
-
factory: PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor('Carbon\Doctrine\CarbonImmutableType')
tags: [phpstan.doctrine.typeDescriptor]
-
factory: PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor('Carbon\Doctrine\CarbonType')
tags: [phpstan.doctrine.typeDescriptor]
-
class: PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidTypeDescriptor
tags: [phpstan.doctrine.typeDescriptor]
Expand Down
32 changes: 25 additions & 7 deletions tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace PHPStan\Rules\Doctrine\ORM;

use Carbon\Doctrine\CarbonImmutableType;
use Carbon\Doctrine\CarbonType;
use Doctrine\DBAL\Types\Type;
use Iterator;
use PHPStan\Rules\Rule;
Expand Down Expand Up @@ -38,22 +40,30 @@ protected function getRule(): Rule
if (!Type::hasType(UuidType::NAME)) {
Type::addType(UuidType::NAME, UuidType::class);
}
if (!Type::hasType('carbon')) {
Type::addType('carbon', \Carbon\Doctrine\CarbonType::class);
}
if (!Type::hasType('carbon_immutable')) {
Type::addType('carbon_immutable', \Carbon\Doctrine\CarbonImmutableType::class);
}

return new EntityColumnRule(
new ObjectMetadataResolver($this->createReflectionProvider(), __DIR__ . '/entity-manager.php', null),
new DescriptorRegistry([
new ArrayType(),
new BigIntType(),
new StringType(),
new DateTimeType(),
new DateTimeImmutableType(),
new BinaryType(),
new DateTimeImmutableType(),
new DateTimeType(),
new DateType(),
new DecimalType(),
new IntegerType(),
new StringType(),
new UuidTypeDescriptor(UuidType::class),
new ReflectionDescriptor(CarbonImmutableType::class, $this->createBroker()),
new ReflectionDescriptor(CarbonType::class, $this->createBroker()),
new ReflectionDescriptor(CustomType::class, $this->createBroker()),
new ReflectionDescriptor(CustomNumericType::class, $this->createBroker()),
new DateType(),
new UuidTypeDescriptor(UuidType::class),
new ArrayType(),
new DecimalType(),
]),
true
);
Expand Down Expand Up @@ -106,6 +116,14 @@ public function testRule(): void
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$numericString type mapping mismatch: database can contain string but property expects string&numeric.',
126,
],
[
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidCarbon type mapping mismatch: database can contain Carbon\Carbon but property expects Carbon\CarbonImmutable.',
132,
],
[
'Property PHPStan\Rules\Doctrine\ORM\MyBrokenEntity::$invalidCarbonImmutable type mapping mismatch: database can contain Carbon\CarbonImmutable but property expects Carbon\Carbon.',
138,
],
]);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/Rules/Doctrine/ORM/data/MyBrokenEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,27 @@ class MyBrokenEntity extends MyBrokenSuperclass
*/
private $numericString;

/**
* @ORM\Column(type="carbon")
* @var \Carbon\CarbonImmutable
*/
private $invalidCarbon;

/**
* @ORM\Column(type="carbon_immutable")
* @var \Carbon\Carbon
*/
private $invalidCarbonImmutable;

/**
* @ORM\Column(type="carbon")
* @var \Carbon\Carbon
*/
private $validCarbon;

/**
* @ORM\Column(type="carbon_immutable")
* @var \Carbon\CarbonImmutable
*/
private $validCarbonImmutable;
}