Skip to content

Commit

Permalink
Enforce literal string for connection execute methods
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and ondrejmirtes committed Apr 15, 2024
1 parent 1667bda commit 45aa443
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 1 deletion.
5 changes: 5 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ parameters:
- Doctrine\ORM\Tools\Pagination\Paginator
stubFiles:
- stubs/Criteria.stub
- stubs/DBAL/Cache/CacheException.stub
- stubs/DBAL/Cache/QueryCacheProfile.stub
- stubs/DBAL/Exception/UniqueConstraintViolationException.stub
- stubs/DBAL/Types/Type.stub
- stubs/DBAL/Exception.stub
- stubs/DBAL/Result.stub
- stubs/DocumentManager.stub
- stubs/DocumentRepository.stub
- stubs/EntityManager.stub
Expand Down
1 change: 1 addition & 0 deletions src/Stubs/Doctrine/StubFilesExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function getFiles(): array
}

$files = [
$path . '/DBAL/Connection.stub',
$path . '/ORM/QueryBuilder.stub',
$path . '/EntityRepository.stub',
];
Expand Down
10 changes: 10 additions & 0 deletions stubs/DBAL/Cache/CacheException.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Doctrine\DBAL\Cache;

use Doctrine\DBAL\Exception;

class CacheException extends Exception
{

}
8 changes: 8 additions & 0 deletions stubs/DBAL/Cache/QueryCacheProfile.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Doctrine\DBAL\Cache;

class QueryCacheProfile
{

}
8 changes: 8 additions & 0 deletions stubs/DBAL/Connection.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Doctrine\DBAL;

class Connection
{

}
8 changes: 8 additions & 0 deletions stubs/DBAL/Exception.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Doctrine\DBAL;

class Exception extends \Exception
{

}
4 changes: 3 additions & 1 deletion stubs/DBAL/Exception/UniqueConstraintViolationException.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Doctrine\DBAL\Exception;

class UniqueConstraintViolationException extends \Exception
use Doctrine\DBAL\Exception;

class UniqueConstraintViolationException extends Exception
{

}
8 changes: 8 additions & 0 deletions stubs/DBAL/Result.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Doctrine\DBAL;

class Result
{

}
7 changes: 7 additions & 0 deletions stubs/DBAL/Types/Type.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Doctrine\DBAL\Types;

abstract class Type
{
}
64 changes: 64 additions & 0 deletions stubs/bleedingEdge/DBAL/Connection.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Doctrine\DBAL;

use Doctrine\DBAL\Cache\CacheException;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Types\Type;

class Connection
{
/**
* Executes an SQL statement with the given parameters and returns the number of affected rows.
*
* Could be used for:
* - DML statements: INSERT, UPDATE, DELETE, etc.
* - DDL statements: CREATE, DROP, ALTER, etc.
* - DCL statements: GRANT, REVOKE, etc.
* - Session control statements: ALTER SESSION, SET, DECLARE, etc.
* - Other statements that don't yield a row set.
*
* This method supports PDO binding types as well as DBAL mapping types.
*
* @param literal-string $sql SQL statement
* @param list<mixed>|array<string, mixed> $params Statement parameters
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @return int|string The number of affected rows.
*
* @throws Exception
*/
public function executeStatement($sql, array $params = [], array $types = []);

/**
* Executes an, optionally parameterized, SQL query.
*
* If the query is parametrized, a prepared statement is used.
* If an SQLLogger is configured, the execution is logged.
*
* @param literal-string $sql SQL query
* @param list<mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @throws Exception
*/
public function executeQuery(
string $sql,
array $params = [],
$types = [],
?QueryCacheProfile $qcp = null
): Result;

/**
* Executes a caching query.
*
* @param literal-string $sql SQL query
* @param list<mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string|Type|null>|array<string, int|string|Type|null> $types Parameter types
*
* @throws CacheException
* @throws Exception
*/
public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp): Result;

}

0 comments on commit 45aa443

Please sign in to comment.