Skip to content

Commit

Permalink
removed(core): InvalidParameterException as removed
Browse files Browse the repository at this point in the history
ref #14074
  • Loading branch information
jeabakker committed Nov 8, 2022
1 parent 3d11203 commit aedb914
Show file tree
Hide file tree
Showing 52 changed files with 248 additions and 275 deletions.
5 changes: 5 additions & 0 deletions docs/appendix/upgrade-notes/4.x-to-5.0.rst
Expand Up @@ -373,6 +373,11 @@ Removed events
* ``access:collections:deletecollection, collection`` use the ``delete, access_collection`` sequence
* ``prepare, breadcrumbs`` use ``register, menu:breadcrumbs``

Removed exceptions
~~~~~~~~~~~~~~~~~~

* ``\Elgg\Exceptions\InvalidParameterException``

Constants
~~~~~~~~~

Expand Down
6 changes: 3 additions & 3 deletions engine/classes/Elgg/Amd/Config.php
Expand Up @@ -2,7 +2,7 @@

namespace Elgg\Amd;

use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\InvalidArgumentException;

/**
* Control configuration of RequireJS
Expand Down Expand Up @@ -93,14 +93,14 @@ public function removePath($name, $path = null) {
* - exports: string Name of the shimmed module to export
*
* @return void
* @throws InvalidParameterException
* @throws InvalidArgumentException
*/
public function addShim(string $name, array $config): void {
$deps = elgg_extract('deps', $config, []);
$exports = elgg_extract('exports', $config);

if (empty($deps) && empty($exports)) {
throw new InvalidParameterException("Shimmed modules must have deps or exports");
throw new InvalidArgumentException("Shimmed modules must have deps or exports");
}

$this->shim[$name] = [];
Expand Down
16 changes: 6 additions & 10 deletions engine/classes/Elgg/Collections/Collection.php
Expand Up @@ -2,20 +2,16 @@

namespace Elgg\Collections;

use ArrayAccess;
use Countable;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\InvalidArgumentException;
use Elgg\Exceptions\OutOfBoundsException;
use SeekableIterator;

/**
* A collection of unique items
*/
class Collection implements CollectionInterface,
ArrayAccess,
SeekableIterator,
Countable {
\ArrayAccess,
\SeekableIterator,
\Countable {

/**
* @var CollectionItemInterface[]
Expand Down Expand Up @@ -59,13 +55,13 @@ public function __construct($items = [], $item_class = null) {
* @param mixed $item Item
*
* @return void
* @throws \Elgg\Exceptions\InvalidParameterException
* @throws \Elgg\Exceptions\InvalidArgumentException
*/
protected function assertValidItem($item) {
$class = $this->item_class ? : CollectionItemInterface::class;
$class = $this->item_class ?? CollectionItemInterface::class;

if (!$item instanceof $class) {
throw new InvalidParameterException('Collection ' . __CLASS__ . ' only accepts instances of ' . $class);
throw new InvalidArgumentException('Collection ' . __CLASS__ . ' only accepts instances of ' . $class);
}
}

Expand Down
6 changes: 3 additions & 3 deletions engine/classes/Elgg/Database/Annotations.php
Expand Up @@ -7,8 +7,8 @@
use Elgg\Database\Clauses\EntityWhereClause;
use Elgg\Database\Clauses\MetadataWhereClause;
use Elgg\Database\Clauses\RelationshipWhereClause;
use Elgg\Exceptions\DomainException;
use Elgg\Exceptions\InvalidArgumentException;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\LogicException;

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ public function count() {
* @param string $property_type 'attribute'|'metadata'|'annotation'
*
* @return int|float
* @throws InvalidParameterException
* @throws DomainException
*/
public function calculate($function, $property, $property_type = null) {

Expand All @@ -64,7 +64,7 @@ public function calculate($function, $property, $property_type = null) {
switch ($property_type) {
case 'attribute':
if (!in_array($property, \ElggEntity::PRIMARY_ATTR_NAMES)) {
throw new InvalidParameterException("'$property' is not a valid attribute");
throw new DomainException("'{$property}' is not a valid attribute");
}

$alias = $qb->joinEntitiesTable('n_table', 'entity_guid', 'inner', 'e');
Expand Down
11 changes: 5 additions & 6 deletions engine/classes/Elgg/Database/Clauses/AnnotationWhereClause.php
Expand Up @@ -2,9 +2,8 @@

namespace Elgg\Database\Clauses;

use DateTime;
use Elgg\Database\QueryBuilder;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\DomainException;

/**
* Builds queries for matching annotations against their properties
Expand Down Expand Up @@ -62,12 +61,12 @@ class AnnotationWhereClause extends WhereClause {
public $case_sensitive = true;

/**
* @var int|string|DateTime
* @var int|string|\DateTime
*/
public $created_after;

/**
* @var int|string|DateTime
* @var int|string|\DateTime
*/
public $created_before;

Expand Down Expand Up @@ -98,7 +97,7 @@ class AnnotationWhereClause extends WhereClause {

/**
* {@inheritdoc}
* @throws InvalidParameterException
* @throws DomainException
*/
public function prepare(QueryBuilder $qb, $table_alias = null) {
$alias = function ($column) use ($table_alias) {
Expand Down Expand Up @@ -126,7 +125,7 @@ public function prepare(QueryBuilder $qb, $table_alias = null) {

if ($this->sort_by_calculation) {
if (!in_array(strtolower($this->sort_by_calculation), QueryBuilder::$calculations)) {
throw new InvalidParameterException("'$this->sort_by_calculation' is not a valid numeric calculation formula");
throw new DomainException("'{$this->sort_by_calculation}' is not a valid numeric calculation formula");
}

$calculation = "{$this->sort_by_calculation}(CAST({$alias('value')} AS DECIMAL(10, 2)))";
Expand Down
6 changes: 3 additions & 3 deletions engine/classes/Elgg/Database/Clauses/ComparisonClause.php
Expand Up @@ -3,7 +3,7 @@
namespace Elgg\Database\Clauses;

use Elgg\Database\QueryBuilder;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\DomainException;
use Elgg\Values;

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ public function __construct($x, $comparison, $y = null, $type = null, $case_sens
/**
* {@inheritdoc}
*
* @throws InvalidParameterException
* @throws DomainException
*/
public function prepare(QueryBuilder $qb, $table_alias = null) {
$x = $this->x;
Expand Down Expand Up @@ -157,7 +157,7 @@ public function prepare(QueryBuilder $qb, $table_alias = null) {
return "NOT EXISTS ($y)";

default :
throw new InvalidParameterException("'{$this->comparison}' is not a supported comparison operator");
throw new DomainException("'{$this->comparison}' is not a supported comparison operator");
}
}
}
11 changes: 6 additions & 5 deletions engine/classes/Elgg/Database/Clauses/EntitySortByClause.php
Expand Up @@ -3,8 +3,7 @@
namespace Elgg\Database\Clauses;

use Elgg\Database\QueryBuilder;
use Elgg\Exceptions\InvalidParameterException;
use ElggEntity;
use Elgg\Exceptions\DomainException;

/**
* Extends QueryBuilder with clauses necesary to sort entity lists by entity properties
Expand Down Expand Up @@ -43,11 +42,13 @@ class EntitySortByClause extends OrderByClause {

/**
* {@inheritdoc}
*
* @throws DomainException
*/
public function prepare(QueryBuilder $qb, $table_alias = null) {

if (!isset($this->property_type)) {
if (in_array($this->property, ElggEntity::PRIMARY_ATTR_NAMES)) {
if (in_array($this->property, \ElggEntity::PRIMARY_ATTR_NAMES)) {
$this->property_type = 'attribute';
} else {
$this->property_type = 'metadata';
Expand Down Expand Up @@ -77,8 +78,8 @@ public function prepare(QueryBuilder $qb, $table_alias = null) {
break;

case 'attribute':
if (!in_array($this->property, ElggEntity::PRIMARY_ATTR_NAMES)) {
throw new InvalidParameterException("'{$this->property}' is not a valid entity attribute");
if (!in_array($this->property, \ElggEntity::PRIMARY_ATTR_NAMES)) {
throw new DomainException("'{$this->property}' is not a valid entity attribute");
}

if ($qb->getTableName() !== QueryBuilder::TABLE_ENTITIES) {
Expand Down
6 changes: 3 additions & 3 deletions engine/classes/Elgg/Database/Entities.php
Expand Up @@ -7,8 +7,8 @@
use Elgg\Database\Clauses\EntityWhereClause;
use Elgg\Database\Clauses\MetadataWhereClause;
use Elgg\Database\Clauses\RelationshipWhereClause;
use Elgg\Exceptions\DomainException;
use Elgg\Exceptions\InvalidArgumentException;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\LogicException;

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ public function count() {
* @param string $property_type 'attribute'|'metadata'|'annotation'
*
* @return string
* @throws InvalidParameterException
* @throws DomainException
*/
public function calculate($function, $property, $property_type = null) {

Expand All @@ -72,7 +72,7 @@ public function calculate($function, $property, $property_type = null) {
switch ($property_type) {
case 'attribute':
if (!in_array($property, \ElggEntity::PRIMARY_ATTR_NAMES)) {
throw new InvalidParameterException("'$property' is not a valid attribute");
throw new DomainException("'{$property}' is not a valid attribute");
}

$qb->addSelect("{$function}(e.{$property}) AS calculation");
Expand Down
10 changes: 5 additions & 5 deletions engine/classes/Elgg/Database/EntityTable.php
Expand Up @@ -11,7 +11,7 @@
use Elgg\EventsService;
use Elgg\Exceptions\ClassException;
use Elgg\Exceptions\Database\UserFetchFailureException;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\DomainException;
use Elgg\I18n\Translator;
use Elgg\Traits\Loggable;
use Elgg\Traits\TimeUsing;
Expand Down Expand Up @@ -119,11 +119,11 @@ public function __construct(
* @param string $class Entity class
*
* @return void
* @throws InvalidParameterException
* @throws DomainException
*/
public function setEntityClass(string $type, string $subtype, string $class = ''): void {
if (!in_array($type, Config::ENTITY_TYPES)) {
throw new InvalidParameterException("{$type} is not a valid entity type");
throw new DomainException("{$type} is not a valid entity type");
}

$this->entity_classes[$type][$subtype] = $class;
Expand Down Expand Up @@ -232,7 +232,7 @@ public function updateRow(int $guid, \stdClass $row) {
*
* @return \ElggEntity|null
* @throws ClassException
* @throws InvalidParameterException
* @throws DomainException
*/
public function rowToElggStar(\stdClass $row): ?\ElggEntity {
if (!isset($row->guid) || !isset($row->subtype)) {
Expand All @@ -256,7 +256,7 @@ public function rowToElggStar(\stdClass $row): ?\ElggEntity {
if (isset($map[$row->type])) {
$class_name = $map[$row->type];
} else {
throw new InvalidParameterException("Entity type {$row->type} is not supported.");
throw new DomainException("Entity type {$row->type} is not supported.");
}
}

Expand Down
6 changes: 3 additions & 3 deletions engine/classes/Elgg/Database/Metadata.php
Expand Up @@ -7,8 +7,8 @@
use Elgg\Database\Clauses\EntityWhereClause;
use Elgg\Database\Clauses\MetadataWhereClause;
use Elgg\Database\Clauses\RelationshipWhereClause;
use Elgg\Exceptions\DomainException;
use Elgg\Exceptions\InvalidArgumentException;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\LogicException;

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ public function count() {
* @param string $property_type 'attribute'|'metadata'|'annotation'
*
* @return int|float
* @throws InvalidParameterException
* @throws DomainException
*/
public function calculate($function, $property, $property_type = null) {

Expand All @@ -64,7 +64,7 @@ public function calculate($function, $property, $property_type = null) {
switch ($property_type) {
case 'attribute':
if (!in_array($property, \ElggEntity::PRIMARY_ATTR_NAMES)) {
throw new InvalidParameterException("'$property' is not a valid attribute");
throw new DomainException("'{$property}' is not a valid attribute");
}

/**
Expand Down
10 changes: 5 additions & 5 deletions engine/classes/Elgg/Database/Mutex.php
Expand Up @@ -3,7 +3,7 @@
namespace Elgg\Database;

use Elgg\Database;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\InvalidArgumentException;
use Elgg\Traits\Loggable;

/**
Expand All @@ -22,7 +22,7 @@ class Mutex {
/**
* @var Database
*/
private $db;
protected $db;

/**
* Constructor
Expand Down Expand Up @@ -89,12 +89,12 @@ public function isLocked(string $namespace): bool {
*
* @param string $namespace Namespace to use for the database table
*
* @throws InvalidParameterException
* @return void
* @throws InvalidArgumentException
*/
private function assertNamespace(string $namespace): void {
protected function assertNamespace(string $namespace): void {
if (!ctype_alpha($namespace)) {
throw new InvalidParameterException("Mutex namespace can only have characters [A-Za-z].");
throw new InvalidArgumentException("Mutex namespace can only have characters [A-Za-z].");
}
}
}
6 changes: 3 additions & 3 deletions engine/classes/Elgg/Database/Relationships.php
Expand Up @@ -7,8 +7,8 @@
use Elgg\Database\Clauses\EntityWhereClause;
use Elgg\Database\Clauses\AnnotationWhereClause;
use Elgg\Database\Clauses\RelationshipWhereClause;
use Elgg\Exceptions\DomainException;
use Elgg\Exceptions\InvalidArgumentException;
use Elgg\Exceptions\InvalidParameterException;
use Elgg\Exceptions\LogicException;

/**
Expand All @@ -22,7 +22,7 @@ class Relationships extends Repository {

/**
* {@inheritDoc}
* @throws InvalidParameterException;
* @throws DomainException
*/
public function calculate($function, $property, $property_type = null) {

Expand All @@ -45,7 +45,7 @@ public function calculate($function, $property, $property_type = null) {
switch ($property_type) {
case 'attribute':
if (!in_array($property, \ElggEntity::PRIMARY_ATTR_NAMES)) {
throw new InvalidParameterException("'$property' is not a valid attribute");
throw new DomainException("'{$property}' is not a valid attribute");
}

$alias = $select->joinEntitiesTable('er', $join_column, 'inner', 'e');
Expand Down

0 comments on commit aedb914

Please sign in to comment.