Skip to content

Fix deprecations #259

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

Merged
merged 1 commit into from
Jun 9, 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 .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'import_functions' => false,
'import_constants' => false,
],
'no_superfluous_phpdoc_tags' => false,
]
)
->setRiskyAllowed(true)
Expand Down
3 changes: 0 additions & 3 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
class="Meilisearch\Bundle\EventListener\DoctrineEventSubscriber"
public="true">
<argument type="service" id="search.service"/>
<argument type="collection"/> <!-- doctrine subscribed events -->
<tag name="doctrine.event_subscriber"/>
<tag name="doctrine_mongodb.odm.event_subscriber"/>
</service>

<service id="search.client" class="Meilisearch\Client" public="true" lazy="true">
Expand Down
47 changes: 1 addition & 46 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ final class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
*/
private array $items;

/**
* @param mixed $items
*/
public function __construct($items = [])
{
$this->items = $this->getArrayableItems($items);
Expand All @@ -30,12 +27,6 @@ public function all(): array
return $this->items;
}

/**
* @param mixed $key
* @param mixed $default
*
* @return mixed
*/
public function get($key, $default = null)
{
if (array_key_exists($key, $this->items)) {
Expand Down Expand Up @@ -151,10 +142,6 @@ public function unique($key = null, bool $strict = false)

/**
* Get the first item from the collection passing the given truth test.
*
* @param mixed $default
*
* @return mixed
*/
public function first(callable $callback = null, $default = null)
{
Expand All @@ -181,27 +168,18 @@ public function first(callable $callback = null, $default = null)
* Get the first item by the given key value pair.
*
* @param string $key
* @param mixed $operator
* @param mixed $value
*
* @return mixed
*/
public function firstWhere($key, $operator = null, $value = null)
{
return $this->first($this->operatorForWhere(...func_get_args()));
}

/**
* @param mixed $offset
*/
public function offsetExists($offset): bool
{
return isset($this->items[$offset]);
}

/**
* @param mixed $offset
*
* @return mixed
*/
#[\ReturnTypeWillChange]
Expand All @@ -210,10 +188,6 @@ public function offsetGet($offset)
return $this->items[$offset];
}

/**
* @param mixed $offset
* @param mixed $value
*/
public function offsetSet($offset, $value): void
{
if (is_null($offset)) {
Expand All @@ -223,9 +197,6 @@ public function offsetSet($offset, $value): void
}
}

/**
* @param mixed $offset
*/
public function offsetUnset($offset): void
{
unset($this->items[$offset]);
Expand All @@ -241,9 +212,6 @@ public function getIterator(): \ArrayIterator
return new \ArrayIterator($this->items);
}

/**
* @param mixed $items
*/
private function getArrayableItems($items): array
{
if (is_array($items)) {
Expand All @@ -269,9 +237,6 @@ private function getArrayableItems($items): array
return (array) $items;
}

/**
* @param mixed $value
*/
private function useAsCallable($value): bool
{
return !is_string($value) && is_callable($value);
Expand All @@ -292,11 +257,7 @@ private function valueRetriever($value)
}

/**
* @param mixed $target
* @param string|array|int|null $key
* @param mixed $default
*
* @return mixed
*/
private static function getDeepData($target, $key, $default = null)
{
Expand Down Expand Up @@ -358,9 +319,6 @@ public static function arrayCollapse(iterable $array): array
return array_merge([], ...$results);
}

/**
* @param mixed $value
*/
public static function accessible($value): bool
{
return is_array($value) || $value instanceof \ArrayAccess;
Expand All @@ -381,10 +339,7 @@ private static function existsInArray($array, $key): bool
return array_key_exists($key, $array);
}

/**
* @param mixed $value
*/
private function operatorForWhere(string $key, ?string $operator = null, $value = null): \Closure
private function operatorForWhere(string $key, string $operator = null, $value = null): \Closure
{
if (1 === func_num_args()) {
$value = true;
Expand Down
10 changes: 6 additions & 4 deletions src/DependencyInjection/MeilisearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
*/
final class MeilisearchExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
Expand All @@ -39,7 +36,12 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('meili_symfony_version', MeilisearchBundle::qualifiedVersion());

if (\count($doctrineEvents = $config['doctrineSubscribedEvents']) > 0) {
$container->getDefinition('search.search_indexer_subscriber')->setArgument(1, $doctrineEvents);
$subscriber = $container->getDefinition('search.search_indexer_subscriber');

foreach ($doctrineEvents as $event) {
$subscriber->addTag('doctrine.event_listener', ['event' => $event]);
$subscriber->addTag('doctrine_mongodb.odm.event_listener', ['event' => $event]);
}
} else {
$container->removeDefinition('search.search_indexer_subscriber');
}
Expand Down
12 changes: 2 additions & 10 deletions src/EventListener/DoctrineEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@

namespace Meilisearch\Bundle\EventListener;

use Doctrine\Common\EventSubscriber;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Meilisearch\Bundle\SearchService;

final class DoctrineEventSubscriber implements EventSubscriber
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to implement this interface anymore? 👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, doctrine has listeners and in Symfony it's enough to tag the class with the appropriate event

final class DoctrineEventSubscriber
{
private SearchService $searchService;
private array $subscribedEvents;

public function __construct(SearchService $searchService, array $subscribedEvents)
public function __construct(SearchService $searchService)
{
$this->searchService = $searchService;
$this->subscribedEvents = $subscribedEvents;
}

public function getSubscribedEvents(): array
{
return $this->subscribedEvents;
}

public function postUpdate(LifecycleEventArgs $args): void
Expand Down
5 changes: 1 addition & 4 deletions src/Model/Aggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ public static function getEntityClassFromObjectID(string $objectId): string
throw new EntityNotFoundInObjectID("Entity class from ObjectID $objectId not found.");
}

/**
* {@inheritdoc}
*/
public function normalize(NormalizerInterface $normalizer, ?string $format = null, array $context = []): array
public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []): array
{
return array_merge(['objectID' => $this->objectID], $normalizer->normalize($this->entity, $format, $context));
}
Expand Down
2 changes: 1 addition & 1 deletion src/SearchableEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
string $indexUid,
$entity,
ClassMetadata $entityMetadata,
?NormalizerInterface $normalizer = null,
NormalizerInterface $normalizer = null,
array $extra = []
) {
$this->indexUid = $indexUid;
Expand Down
9 changes: 0 additions & 9 deletions src/Services/MeilisearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public function __construct(NormalizerInterface $normalizer, Engine $engine, arr
$this->setIndexIfMapping();
}

/**
* {@inheritdoc}
*/
public function isSearchable($className): bool
{
if (is_object($className)) {
Expand All @@ -68,9 +65,6 @@ public function getConfiguration(): Collection
return $this->configuration;
}

/**
* {@inheritdoc}
*/
public function searchableAs(string $className): string
{
$indexes = new Collection($this->getConfiguration()->get('indices'));
Expand Down Expand Up @@ -185,9 +179,6 @@ public function search(
return $results;
}

/**
* {@inheritdoc}
*/
public function rawSearch(
string $className,
string $query = '',
Expand Down
3 changes: 0 additions & 3 deletions tests/Entity/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public function setIsSponsored(bool $isSponsored): Link
return $this;
}

/**
* {@inheritDoc}
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []): array
{
if (Searchable::NORMALIZATION_FORMAT === $format) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Entity/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Page
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'NONE')]
#[ORM\Column(type: Types::OBJECT)]
private $id = null;
private $id;

/**
* @ORM\Column(type="string", nullable=true)
Expand Down
2 changes: 0 additions & 2 deletions tests/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ public function setPublic(bool $public): Tag
}

/**
* {@inheritDoc}
*
* @throws ExceptionInterface
*/
public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []): array
Expand Down
14 changes: 7 additions & 7 deletions tests/Integration/EventListener/DoctrineEventSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Meilisearch\Bundle\Tests\Integration\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Meilisearch\Bundle\EventListener\DoctrineEventSubscriber;
use Meilisearch\Bundle\Tests\BaseKernelTestCase;
use Meilisearch\Bundle\Tests\Entity\Page;
Expand Down Expand Up @@ -35,7 +35,7 @@ public function testPostPersist(): void

$eventArgs = new LifecycleEventArgs($post, $this->entityManager);

$subscriber = new DoctrineEventSubscriber($this->searchService, []);
$subscriber = new DoctrineEventSubscriber($this->searchService);
$subscriber->postPersist($eventArgs);

$this->waitForAllTasks();
Expand All @@ -53,7 +53,7 @@ public function testPostPersistWithObjectId(): void

$eventArgs = new LifecycleEventArgs($page, $this->entityManager);

$subscriber = new DoctrineEventSubscriber($this->searchService, []);
$subscriber = new DoctrineEventSubscriber($this->searchService);
$subscriber->postPersist($eventArgs);

$this->waitForAllTasks();
Expand All @@ -74,7 +74,7 @@ public function testPostUpdate(): void

$eventArgs = new LifecycleEventArgs($post, $this->entityManager);

$subscriber = new DoctrineEventSubscriber($this->searchService, []);
$subscriber = new DoctrineEventSubscriber($this->searchService);
$subscriber->postUpdate($eventArgs);

$this->waitForAllTasks();
Expand All @@ -92,7 +92,7 @@ public function testPostUpdateWithObjectId(): void

$eventArgs = new LifecycleEventArgs($page, $this->entityManager);

$subscriber = new DoctrineEventSubscriber($this->searchService, []);
$subscriber = new DoctrineEventSubscriber($this->searchService);
$subscriber->postUpdate($eventArgs);

$this->waitForAllTasks();
Expand All @@ -113,7 +113,7 @@ public function testPreRemove(): void

$eventArgs = new LifecycleEventArgs($post, $this->entityManager);

$subscriber = new DoctrineEventSubscriber($this->searchService, []);
$subscriber = new DoctrineEventSubscriber($this->searchService);
$subscriber->postPersist($eventArgs);

$this->waitForAllTasks();
Expand All @@ -138,7 +138,7 @@ public function testPreRemoveWithObjectId(): void

$eventArgs = new LifecycleEventArgs($page, $this->entityManager);

$subscriber = new DoctrineEventSubscriber($this->searchService, []);
$subscriber = new DoctrineEventSubscriber($this->searchService);
$subscriber->postPersist($eventArgs);

$this->waitForAllTasks();
Expand Down
2 changes: 0 additions & 2 deletions tests/Integration/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class SearchTest extends BaseKernelTestCase
protected Indexes $index;

/**
* {@inheritDoc}
*
* @throws ApiException
* @throws \Exception
*/
Expand Down
2 changes: 0 additions & 2 deletions tests/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
class Kernel extends HttpKernel
{
/**
* {@inheritDoc}
*
* @return array<int, BundleInterface>
*/
public function registerBundles(): array
Expand Down
3 changes: 0 additions & 3 deletions tests/Unit/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class ConfigurationTest extends KernelTestCase
{
/**
* @dataProvider dataTestConfigurationTree
*
* @param mixed $inputConfig
* @param mixed $expectedConfig
*/
public function testConfigurationTree($inputConfig, $expectedConfig): void
{
Expand Down
5 changes: 5 additions & 0 deletions tests/baseline-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the stack expert here, you probably had reasons for skipping those warnings here, and I will agree with them. But I would like to have a process or at least know how to avoid those additions. Because to me, this kind of file only grows indefinitely.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it will be reduced later. There are some indirect deprecations that cannot be fixed and need to wait upstream fix

Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
%The "Symfony\\Component\\HttpClient\\HttplugClient" class implements "Http\\Message\\RequestFactory" that is deprecated since version 1.1, use Psr\\Http\\Message\\RequestFactoryInterface instead.%
%The "Symfony\\Component\\HttpClient\\HttplugClient" class implements "Http\\Message\\StreamFactory" that is deprecated since version 1.1, use Psr\\Http\\Message\\StreamFactoryInterface instead.%
%The "Symfony\\Component\\HttpClient\\HttplugClient" class implements "Http\\Message\\UriFactory" that is deprecated since version 1.1, use Psr\\Http\\Message\\UriFactoryInterface instead.%
%Doctrine\\DBAL\\Platforms\\AbstractPlatform::usesSequenceEmulatedIdentityColumns is deprecated. \(AbstractPlatform.php:\d+ called by ClassMetadataFactory.php:\d+, https://github.com/doctrine/dbal/pull/5513, package doctrine/dbal\)%
%Column::setCustomSchemaOptions\(\) is deprecated. Use setPlatformOptions\(\) instead. \(Column.php:\d+ called by Column.php:\d+, https://github.com/doctrine/dbal/pull/5476, package doctrine/dbal\)%
%SqlitePlatform::canEmulateSchemas\(\) is deprecated. \(SqlitePlatform.php:\d+ called by SchemaTool.php:\d+, https://github.com/doctrine/dbal/pull/4805, package doctrine/dbal\)%
%Doctrine\\DBAL\\Schema\\Table::getPrimaryKeyColumns is deprecated. Use getPrimaryKey\(\) and Index::getColumns\(\) instead. \(Table.php:\d+ called by Table.php:\d+, https://github.com/doctrine/dbal/pull/5731, package doctrine/dbal\)%
%The annotation mapping driver is deprecated and will be removed in Doctrine ORM 3.0, please migrate to the attribute or XML driver. \(AnnotationDriver.php:\d+ called by getDoctrine_Orm_DefaultAnnotationMetadataDriverService.php:20, https://github.com/doctrine/orm/issues/10098, package doctrine/orm\)%
3 changes: 2 additions & 1 deletion tests/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ doctrine:
path: '%kernel.cache_dir%/test.sqlite'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
Expand Down
Loading