Skip to content

Commit

Permalink
Extract factory methods from Doctrine\DBAL\SQLParserUtilsException
Browse files Browse the repository at this point in the history
Extract Doctrine\DBAL\SQLParserUtilsException::missingParam()
Extract Doctrine\DBAL\SQLParserUtilsException::missingType()
  • Loading branch information
Majkl578 committed May 12, 2018
1 parent e48f134 commit 7b5f2f8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
18 changes: 18 additions & 0 deletions lib/Doctrine/DBAL/Exception/MissingSQLParam.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Exception;

use Doctrine\DBAL\SQLParserUtilsException;
use function sprintf;

final class MissingSQLParam extends SQLParserUtilsException
{
public static function new(string $paramName) : self
{
return new self(
sprintf('Value for :%1$s not found in params array. Params array key should be "%1$s"', $paramName)
);
}
}
18 changes: 18 additions & 0 deletions lib/Doctrine/DBAL/Exception/MissingSQLType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Exception;

use Doctrine\DBAL\SQLParserUtilsException;
use function sprintf;

final class MissingSQLType extends SQLParserUtilsException
{
public static function new(string $typeName) : self
{
return new self(
sprintf('Value for :%1$s not found in types array. Types array key should be "%1$s"', $typeName)
);
}
}
6 changes: 4 additions & 2 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Doctrine\DBAL;

use Doctrine\DBAL\Exception\MissingSQLParam;
use Doctrine\DBAL\Exception\MissingSQLType;
use const PREG_OFFSET_CAPTURE;
use function array_fill;
use function array_key_exists;
Expand Down Expand Up @@ -236,9 +238,9 @@ private static function extractParam($paramName, $paramsOrTypes, $isParam, $defa
}

if ($isParam) {
throw SQLParserUtilsException::missingParam($paramName);
throw MissingSQLParam::new($paramName);
}

throw SQLParserUtilsException::missingType($paramName);
throw MissingSQLType::new($paramName);
}
}
19 changes: 0 additions & 19 deletions lib/Doctrine/DBAL/SQLParserUtilsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,4 @@
*/
class SQLParserUtilsException extends DBALException
{
/**
* @param string $paramName
*
* @return \Doctrine\DBAL\SQLParserUtilsException
*/
public static function missingParam($paramName)
{
return new self(sprintf('Value for :%1$s not found in params array. Params array key should be "%1$s"', $paramName));
}

/**
* @param string $typeName
*
* @return \Doctrine\DBAL\SQLParserUtilsException
*/
public static function missingType($typeName)
{
return new self(sprintf('Value for :%1$s not found in types array. Types array key should be "%1$s"', $typeName));
}
}

0 comments on commit 7b5f2f8

Please sign in to comment.