-
Notifications
You must be signed in to change notification settings - Fork 22
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
bump to php7.4 #24
base: master
Are you sure you want to change the base?
bump to php7.4 #24
Changes from all commits
107b56b
77b44b8
3cfaf85
7649ec3
fc0b39c
1b5f993
c00a464
12eee1f
0006b96
c7aa70b
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,9 @@ | ||
parameters: | ||
level: 0 | ||
# inferPrivatePropertyTypeFromConstructor: true | ||
paths: | ||
- ./src | ||
excludePaths: | ||
- 'src/Resources/skeleton' | ||
- */cache/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; | ||
use Rector\Config\RectorConfig; | ||
use Rector\Set\ValueObject\LevelSetList; | ||
use Rector\PHPUnit\Set\PHPUnitSetList; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
__DIR__ . '/src' | ||
]); | ||
|
||
// register a single rule | ||
// $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); | ||
|
||
// define sets of rules | ||
$rectorConfig->sets([ | ||
PHPUnitSetList::PHPUNIT_80, | ||
LevelSetList::UP_TO_PHP_74 | ||
]); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Core\Configuration\Option; | ||
use Rector\Php74\Rector\Property\TypedPropertyRector; | ||
use Rector\Set\ValueObject\LevelSetList; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
use Rector\PHPUnit\Set\PHPUnitSetList; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
// get parameters | ||
$parameters = $containerConfigurator->parameters(); | ||
$parameters->set(Option::PATHS, [ | ||
__DIR__ . '/tests', | ||
__DIR__ . '/src', | ||
]); | ||
|
||
// Define what rule sets will be applied | ||
|
||
// rector.php | ||
// $containerConfigurator->import(LevelSetList::UP_TO_PHP_74); | ||
$containerConfigurator->import(PHPUnitSetList::PHPUNIT_50); | ||
|
||
// get services (needed for register a single rule) | ||
// $services = $containerConfigurator->services(); | ||
|
||
// register a single rule | ||
// $services->set(TypedPropertyRector::class); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
namespace VertigoLabs\DoctrineFullTextPostgres\Common; | ||
|
||
use App\Entity\Media; | ||
use Doctrine\Common\Annotations\AnnotationException; | ||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Doctrine\Common\Annotations\AnnotationRegistry; | ||
|
@@ -60,7 +61,7 @@ public function __construct() | |
* | ||
* @return array | ||
*/ | ||
public function getSubscribedEvents() | ||
public function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
Events::loadClassMetadata, | ||
|
@@ -73,9 +74,40 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) | |
{ | ||
/** @var ClassMetadata $metaData */ | ||
$metaData = $eventArgs->getClassMetadata(); | ||
|
||
$class = $metaData->getReflectionClass(); | ||
|
||
foreach ($class->getProperties() as $prop) { | ||
// check for php8 attributes on the class properties | ||
if (method_exists($prop, 'getAttributes')) { | ||
foreach ($prop->getAttributes() as $reflectionAttribute) { | ||
if ($reflectionAttribute->getName() === TsVector::class) { | ||
// /** @var TsVector $attribute */ | ||
$attribute = new ($reflectionAttribute->getName())(...$reflectionAttribute->getArguments()); // crazy, something is wrong here. | ||
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. I'm a little apprehensive about this comment! 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. No doubt! I'll see if I can figure it out. I'm fighting a little bit with supporting both attributes and annotations, I think that attributes should take priority if both exist. |
||
$this->checkWatchFields($class, $prop, $attribute); | ||
|
||
$metaData->mapField([ | ||
'fieldName' => $prop->getName(), | ||
'columnName' => $this->getColumnName($prop, $attribute), | ||
'type' => 'tsvector', | ||
'weight' => strtoupper($attribute->weight), | ||
'language' => strtolower($attribute->language), | ||
'nullable' => true, // pre-populating $this->isWatchFieldNullable($class, $attribute) | ||
]); | ||
|
||
} | ||
} | ||
} | ||
|
||
// $this->checkWatchFields($class, $prop, $attribute); | ||
// $metaData->mapField([ | ||
// 'fieldName' => $prop->getName(), | ||
// 'columnName' => $this->getColumnName($prop, $annotation), | ||
// 'type' => 'tsvector', | ||
// 'weight' => strtoupper($annotation->weight), | ||
// 'language' => strtolower($annotation->language), | ||
// 'nullable' => $this->isWatchFieldNullable($class, $annotation) | ||
// ]); | ||
|
||
Comment on lines
+101
to
+110
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. Commented out code should be removed |
||
/** @var TsVector $annotation */ | ||
$annotation = $this->reader->getPropertyAnnotation($prop, self::ANNOTATION_NS.self::ANNOTATION_TSVECTOR); | ||
if (null === $annotation) { | ||
|
@@ -161,30 +193,53 @@ private function getColumnName(\ReflectionProperty $property, TsVector $annotati | |
return $name; | ||
} | ||
|
||
private function checkWatchFields(\ReflectionClass $class, \ReflectionProperty $targetProperty, TsVector $annotation) | ||
private function checkWatchFields(\ReflectionClass $reflectionClass, \ReflectionProperty $targetProperty, TsVector $annotation) | ||
{ | ||
foreach ($reflectionClass->getAttributes(\VertigoLabs\DoctrineFullTextPostgres\ORM\Attribute\TsVector::class) as $attribute) { | ||
dd($attribute); | ||
} | ||
|
||
foreach ($annotation->fields as $fieldName) { | ||
if ($class->hasMethod($fieldName)) { | ||
if ($reflectionClass->hasMethod($fieldName)) { | ||
continue; | ||
} | ||
|
||
if (!$class->hasProperty($fieldName)) { | ||
if (!$reflectionClass->hasProperty($fieldName)) { | ||
throw new MappingException(sprintf('Class does not contain %s property or getter', $fieldName)); | ||
} | ||
|
||
$property = $class->getProperty($fieldName); | ||
$reflectionProperty = $reflectionClass->getProperty($fieldName); | ||
|
||
/** @var Column $propAnnot */ | ||
$propAnnot = $this->reader->getPropertyAnnotation($property, Column::class); | ||
if (!in_array($propAnnot->type, self::$supportedTypes)) { | ||
throw new AnnotationException(sprintf( | ||
'%s::%s TsVector field can only be assigned to ( "%s" ) columns. %1$s::%s has the type %s', | ||
$class->getName(), | ||
$targetProperty->getName(), | ||
implode('" | "', self::$supportedTypes), | ||
$fieldName, | ||
$propAnnot->type | ||
)); | ||
if (!$propAnnot = $this->reader->getPropertyAnnotation($reflectionProperty, Column::class)) { | ||
foreach ($reflectionProperty->getAttributes(Column::class) as $columnAttribute) { | ||
if (!in_array($columnAttribute->getArguments()['type'], self::$supportedTypes)) { | ||
throw new AnnotationException(sprintf( | ||
'%s::%s TsVector field can only be assigned to ( "%s" ) columns. %1$s::%s has the type %s', | ||
$reflectionClass->getName(), | ||
$targetProperty->getName(), | ||
implode('" | "', self::$supportedTypes), | ||
$fieldName, | ||
$propAnnot->type | ||
)); | ||
} | ||
|
||
} | ||
} else { | ||
// use annotation | ||
if (!in_array($propAnnot->type, self::$supportedTypes)) { | ||
throw new AnnotationException(sprintf( | ||
'%s::%s TsVector field can only be assigned to ( "%s" ) columns. %1$s::%s has the type %s', | ||
$reflectionClass->getName(), | ||
$targetProperty->getName(), | ||
implode('" | "', self::$supportedTypes), | ||
$fieldName, | ||
$propAnnot->type | ||
)); | ||
} | ||
} | ||
|
||
|
||
} | ||
} | ||
|
||
|
@@ -197,9 +252,19 @@ private function isWatchFieldNullable(\ReflectionClass $class, TsVector $annotat | |
|
||
$property = $class->getProperty($fieldName); | ||
/** @var Column $propAnnot */ | ||
$propAnnot = $this->reader->getPropertyAnnotation($property, Column::class); | ||
if (false === $propAnnot->nullable) { | ||
return false; | ||
if ($propAnnot = $this->reader->getPropertyAnnotation($property, Column::class)) { | ||
if (false === $propAnnot->nullable) { | ||
return false; | ||
} | ||
} else { | ||
$reflectionProperty = $class->getProperty($fieldName); | ||
foreach ($reflectionProperty->getAttributes(Column::class) as $propAttr) { | ||
$attr = $propAttr->getArguments(); | ||
if (false === $attr['nullable'] ?? false) { | ||
return false; | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
|
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.
This line shouldn't exist