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

[WIP] Orm querybuilder set parameters to collection v2 #346

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

Copy link
Member

Choose a reason for hiding this comment

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

like other PR, please add namespace if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will rebase this PR and apply all the fixes after the other one is done if this is fine for you

final class QueryBuilderCall
{
public function createCustomQueryBuilder()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters([
new \Doctrine\ORM\Query\Parameter('foo', 'bar'),
new \Doctrine\ORM\Query\Parameter('bar', 1),
new \Doctrine\ORM\Query\Parameter('baz', false),
]);
}
}
?>
-----
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilder()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters(new \Doctrine\Common\Collections\ArrayCollection([new \Doctrine\ORM\Query\Parameter('foo', 'bar'), new \Doctrine\ORM\Query\Parameter('bar', 1), new \Doctrine\ORM\Query\Parameter('baz', false)]));
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

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

use underscored fixture file name instead of dash


final class QueryBuilderCall
{
public function createCustomQueryBuilder()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters(new \Doctrine\Common\Collections\ArrayCollection([
'foo' => 'bar',
'bar' => 1,
'baz' => false
]));
}
}
?>
-----
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilder()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters(new \Doctrine\Common\Collections\ArrayCollection([new \Doctrine\ORM\Query\Parameter('foo', 'bar'), new \Doctrine\ORM\Query\Parameter('bar', 1), new \Doctrine\ORM\Query\Parameter('baz', false)]));
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilderWithDynamicArray()
{
$ormQueryBuilder = new class {

};

$params = ['name' => 'John'];
if (true) {
$ormQueryBuilder->andWhere('age > :age');
$params['age'] = 18;
}
$params['lastName'] = 'bar';
$ormQueryBuilder->setParameters($params);
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilderWithDynamicArray()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();

$params = ['name' => 'John'];
if (true) {
$ormQueryBuilder->andWhere('age > :age');
$params['age'] = 18;
}
$params['lastName'] = 'bar';
$ormQueryBuilder->setParameters($params);
}
}
?>
-----
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilderWithDynamicArray()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();

$params = new \Doctrine\Common\Collections\ArrayCollection([new \Doctrine\ORM\Query\Parameter('name', 'John')]);
if (true) {
$ormQueryBuilder->andWhere('age > :age');
$params->add(new \Doctrine\ORM\Query\Parameter('age', 18));
}
$params->add(new \Doctrine\ORM\Query\Parameter('lastName', 'bar'));
$ormQueryBuilder->setParameters($params);
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilder()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters([
'foo' => 'bar',
'bar' => 1,
'baz' => false
]);
}
}
?>
-----
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilder()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters(new \Doctrine\Common\Collections\ArrayCollection([new \Doctrine\ORM\Query\Parameter('foo', 'bar'), new \Doctrine\ORM\Query\Parameter('bar', 1), new \Doctrine\ORM\Query\Parameter('baz', false)]));
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilder()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters(new \Doctrine\Common\Collections\ArrayCollection([
new \Doctrine\ORM\Query\Parameter('foo', 'bar'),
new \Doctrine\ORM\Query\Parameter('bar', 1),
new \Doctrine\ORM\Query\Parameter('baz', false),
]));
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilderWithNumeric()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters([
'one',
'two',
'three'
]);
}
}
?>
-----
<?php

final class QueryBuilderCall
{
public function createCustomQueryBuilderWithNumeric()
{
$ormQueryBuilder = new \Doctrine\ORM\QueryBuilder();
$ormQueryBuilder->setParameters(new \Doctrine\Common\Collections\ArrayCollection([new \Doctrine\ORM\Query\Parameter(0, 'one'), new \Doctrine\ORM\Query\Parameter(1, 'two'), new \Doctrine\ORM\Query\Parameter(2, 'three')]));
}
}
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Rector\Doctrine\Tests\Orm30\Rector\MethodCall\SetParametersArrayToCollectionRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class SetParametersArrayToCollectionRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixtures');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withRules([\Rector\Doctrine\Orm30\Rector\MethodCall\SetParametersArrayToCollectionRector::class]);
Loading
Loading