Browse Source

`InvalidParamException` usage removed

tags/3.0.0-alpha1
Klimov Paul 7 years ago
parent
commit
f1a738ec07
  1. 4
      framework/db/Query.php
  2. 6
      framework/db/SqlTokenizer.php
  3. 2
      framework/db/pgsql/QueryBuilder.php
  4. 32
      framework/i18n/Formatter.php
  5. 4
      framework/rbac/BaseManager.php
  6. 3
      tests/framework/db/GetTablesAliasTestTrait.php
  7. 6
      tests/framework/rbac/ManagerTestCase.php

4
framework/db/Query.php

@ -10,7 +10,7 @@ namespace yii\db;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\InvalidArgumentException;
/**
* Query represents a SELECT SQL statement in a way that is independent of DBMS.
@ -537,7 +537,7 @@ PATTERN;
if ($tableName instanceof Expression) {
if (!is_string($alias)) {
throw new InvalidParamException('To use Expression in from() method, pass it in array format with alias.');
throw new InvalidArgumentException('To use Expression in from() method, pass it in array format with alias.');
}
$cleanedUpTableNames[$this->ensureNameQuoted($alias)] = $tableName;
} elseif ($tableName instanceof self) {

6
framework/db/SqlTokenizer.php

@ -8,7 +8,7 @@
namespace yii\db;
use yii\base\Component;
use yii\base\InvalidParamException;
use yii\base\InvalidArgumentException;
/**
* SqlTokenizer splits an SQL query into individual SQL tokens.
@ -371,12 +371,12 @@ abstract class SqlTokenizer extends Component
/**
* Adds the specified length to the current offset.
* @param int $length
* @throws InvalidParamException
* @throws InvalidArgumentException
*/
private function advance($length)
{
if ($length <= 0) {
throw new InvalidParamException('Length must be greater than 0.');
throw new InvalidArgumentException('Length must be greater than 0.');
}
$this->offset += $length;

2
framework/db/pgsql/QueryBuilder.php

@ -7,7 +7,7 @@
namespace yii\db\pgsql;
use yii\base\InvalidParamException;
use yii\base\InvalidArgumentException;
use yii\helpers\StringHelper;
/**

32
framework/i18n/Formatter.php

@ -646,7 +646,7 @@ class Formatter extends Component
* PHP [date()](http://php.net/manual/en/function.date.php)-function.
*
* @return string the formatted result.
* @throws InvalidParamException if the input value can not be evaluated as a date value.
* @throws InvalidArgumentException if the input value can not be evaluated as a date value.
* @throws InvalidConfigException if the date format is invalid.
* @see timeFormat
*/
@ -802,7 +802,7 @@ class Formatter extends Component
* the timestamp has time information or it is just a date value.
* Since version 2.0.12 the array has third boolean element indicating whether the timestamp has date information
* or it is just a time value.
* @throws InvalidParamException if the input value can not be evaluated as a date value.
* @throws InvalidArgumentException if the input value can not be evaluated as a date value.
*/
protected function normalizeDatetimeValue($value, $checkDateTimeInfo = false)
{
@ -1167,7 +1167,7 @@ class Formatter extends Component
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
*/
public function asScientific($value, $decimals = null, $options = [], $textOptions = [])
{
@ -1179,7 +1179,7 @@ class Formatter extends Component
if ($this->_intlLoaded) {
$f = $this->createNumberFormatter(NumberFormatter::SCIENTIFIC, $decimals, $options, $textOptions);
if (($result = $f->format($value)) === false) {
throw new InvalidParamException('Formatting scientific number value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
throw new InvalidArgumentException('Formatting scientific number value failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
}
return $result;
@ -1204,7 +1204,7 @@ class Formatter extends Component
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException if no currency is given and [[currencyCode]] is not defined.
*/
public function asCurrency($value, $currency = null, $options = [], $textOptions = [])
@ -1228,7 +1228,7 @@ class Formatter extends Component
$result = $formatter->formatCurrency($value, $currency);
}
if ($result === false) {
throw new InvalidParamException('Formatting currency value failed: ' . $formatter->getErrorCode() . ' ' . $formatter->getErrorMessage());
throw new InvalidArgumentException('Formatting currency value failed: ' . $formatter->getErrorCode() . ' ' . $formatter->getErrorMessage());
}
return $result;
@ -1251,7 +1251,7 @@ class Formatter extends Component
*
* @param mixed $value the value to be formatted
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available.
*/
public function asSpellout($value)
@ -1263,7 +1263,7 @@ class Formatter extends Component
if ($this->_intlLoaded) {
$f = $this->createNumberFormatter(NumberFormatter::SPELLOUT);
if (($result = $f->format($value)) === false) {
throw new InvalidParamException('Formatting number as spellout failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
throw new InvalidArgumentException('Formatting number as spellout failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
}
return $result;
@ -1279,7 +1279,7 @@ class Formatter extends Component
*
* @param mixed $value the value to be formatted
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when the [PHP intl extension](http://php.net/manual/en/book.intl.php) is not available.
*/
public function asOrdinal($value)
@ -1291,7 +1291,7 @@ class Formatter extends Component
if ($this->_intlLoaded) {
$f = $this->createNumberFormatter(NumberFormatter::ORDINAL);
if (($result = $f->format($value)) === false) {
throw new InvalidParamException('Formatting number as ordinal failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
throw new InvalidArgumentException('Formatting number as ordinal failed: ' . $f->getErrorCode() . ' ' . $f->getErrorMessage());
}
return $result;
@ -1313,7 +1313,7 @@ class Formatter extends Component
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @see sizeFormatBase
* @see asSize
*/
@ -1424,7 +1424,7 @@ class Formatter extends Component
* @param array $numberOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not contain required information.
* @see asLength
* @since 2.0.13
@ -1447,7 +1447,7 @@ class Formatter extends Component
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not contain required information.
* @see asLength
* @since 2.0.13
@ -1468,7 +1468,7 @@ class Formatter extends Component
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not contain required information.
* @since 2.0.13
* @author John Was <janek.jan@gmail.com>
@ -1490,7 +1490,7 @@ class Formatter extends Component
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return string the formatted result.
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
* @throws InvalidConfigException when INTL is not installed or does not contain required information.
* @since 2.0.13
* @author John Was <janek.jan@gmail.com>
@ -1597,7 +1597,7 @@ class Formatter extends Component
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
* @param array $textOptions optional configuration for the number formatter. This parameter will be merged with [[numberFormatterTextOptions]].
* @return array [parameters for Yii::t containing formatted number, internal position of size unit]
* @throws InvalidParamException if the input value is not numeric or the formatting failed.
* @throws InvalidArgumentException if the input value is not numeric or the formatting failed.
*/
private function formatNumber($value, $decimals, $maxPosition, $formatBase, $options, $textOptions)
{

4
framework/rbac/BaseManager.php

@ -207,11 +207,11 @@ abstract class BaseManager extends Component implements ManagerInterface
} elseif (is_callable($roles)) {
$roles = $roles();
if (!is_array($roles)) {
throw new InvalidParamException('Default roles closure must return an array');
throw new InvalidArgumentException('Default roles closure must return an array');
}
$this->defaultRoles = $roles;
} else {
throw new InvalidParamException('Default roles must be either an array or a callable');
throw new InvalidArgumentException('Default roles must be either an array or a callable');
}
}

3
tests/framework/db/GetTablesAliasTestTrait.php

@ -7,6 +7,7 @@
namespace yiiunit\framework\db;
use yii\base\InvalidArgumentException;
use yii\db\ActiveQuery;
use yii\db\Query;
@ -132,7 +133,7 @@ trait GetTablesAliasTestTrait
$expression = new \yii\db\Expression('(SELECT id FROM user)');
$query->from = $expression;
$this->expectException('yii\base\InvalidParamException');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('To use Expression in from() method, pass it in array format with alias.');
$tables = $query->getTablesUsedInFrom();

6
tests/framework/rbac/ManagerTestCase.php

@ -7,7 +7,7 @@
namespace yiiunit\framework\rbac;
use yii\base\InvalidParamException;
use yii\base\InvalidArgumentException;
use yii\rbac\Item;
use yii\rbac\Permission;
use yii\rbac\Role;
@ -620,7 +620,7 @@ abstract class ManagerTestCase extends TestCase
try {
$this->auth->defaultRoles = 'test';
} catch (\Exception $e) {
$this->assertInstanceOf('\yii\base\InvalidParamException', $e);
$this->assertInstanceOf(InvalidArgumentException::class, $e);
$this->assertEquals('Default roles must be either an array or a callable', $e->getMessage());
try {
@ -628,7 +628,7 @@ abstract class ManagerTestCase extends TestCase
return 'test';
};
} catch (\Exception $e) {
$this->assertInstanceOf('\yii\base\InvalidParamException', $e);
$this->assertInstanceOf(InvalidArgumentException::class, $e);
$this->assertEquals('Default roles closure must return an array', $e->getMessage());
}

Loading…
Cancel
Save