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

types, better error message and fix for numerial key in find #7

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 10 additions & 5 deletions lib/Horde/Rdo/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ public function __get($field)
} elseif (!empty($this->{$rel['foreignKey']})) {
$this->_fields[$field] = $m->findOne($this->{$rel['foreignKey']});
if (empty($this->_fields[$field])) {
throw new Horde_Rdo_Exception('The referenced object with key ' . $this->{$rel['foreignKey']} . ' does not exist. Your data is inconsistent');
throw new Horde_Rdo_Exception(sprintf(
'The referenced object of %s instance with key %s = %s does not exist. Your data is inconsistent',
get_class($this),

Choose a reason for hiding this comment

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

I'd prefer using the ::class magic property over get_class but otherwise I like this.

$rel['foreignKey'],
$this->{$rel['foreignKey']},
));
}
} else {
$this->_fields[$field] = null;
Expand Down Expand Up @@ -189,7 +194,7 @@ public function __set($field, $value)
*
* @see __set()
*/
public function offsetSet($field, $value)
public function offsetSet($field, $value): void
{
$this->__set($field, $value);
}
Expand All @@ -215,7 +220,7 @@ public function __isset($field)
*
* @see __isset()
*/
public function offsetExists($field)
public function offsetExists($field): bool
{
return $this->__isset($field);
}
Expand All @@ -238,7 +243,7 @@ public function __unset($field)
*
* @see __unset()
*/
public function offsetUnset($field)
public function offsetUnset($field): void
{
$this->__unset($field);
}
Expand All @@ -261,7 +266,7 @@ public function setFields($fields = array())
*
* @return Horde_Rdo_Iterator The Iterator instance.
*/
public function getIterator()
public function getIterator(): Traversable
{
return new Horde_Rdo_Iterator($this);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Horde/Rdo/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($rdo)
/**
* Reset to the first key.
*/
public function rewind()
public function rewind(): void
{
$this->_valid = (false !== reset($this->_keys));
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public function key()
/**
* Move to the next key in the iterator.
*/
public function next()
public function next(): void
{
$this->_valid = (false !== next($this->_keys));
}
Expand All @@ -97,7 +97,7 @@ public function next()
*
* @return boolean Inside array bounds?
*/
public function valid()
public function valid(): bool
{
return $this->_valid;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/Horde/Rdo/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function __destruct()
/**
* Implementation of the rewind() method for iterator.
*/
public function rewind()
public function rewind(): void
{
if ($this->_result) {
unset($this->_result);
Expand Down Expand Up @@ -167,7 +167,7 @@ public function key()
* @return Horde_Rdo_Base|null The next Rdo object in the set or
* null if no more results.
*/
public function next()
public function next(): void
{
if (is_null($this->_result)) {
$this->rewind();
Expand All @@ -190,7 +190,7 @@ public function next()
}
}

return $this->_current;
// return $this->_current;
}

/**
Expand All @@ -200,7 +200,7 @@ public function next()
*
* @return boolean Whether or not an offset exists.
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
$query = Horde_Rdo_Query::create($this->_query);
$query->limit(1, $offset);
Expand Down Expand Up @@ -232,7 +232,7 @@ public function offsetGet($offset)
*
* @return Horde_Rdo_Base An entity object at the offset position or null
*/
public function offsetSet($offset, $item)
public function offsetSet($offset, $item): void
{
throw new Horde_Rdo_Exception('You cannot add objects to a result set');
}
Expand All @@ -247,7 +247,7 @@ public function offsetSet($offset, $item)
*
* @return Horde_Rdo_Base An entity object at the offset position or null
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
throw new Horde_Rdo_Exception('You cannot remove objects from a result set');
}
Expand All @@ -257,7 +257,7 @@ public function offsetUnset($offset)
*
* @return boolean Whether the iteration is valid
*/
public function valid()
public function valid(): bool
{
if (is_null($this->_result)) {
$this->rewind();
Expand All @@ -270,7 +270,7 @@ public function valid()
*
* @return integer Number of elements in the list
*/
public function count()
public function count(): int
{
if (is_null($this->_count)) {
$this->_count = $this->_mapper->count($this->_query);
Expand Down
5 changes: 1 addition & 4 deletions lib/Horde/Rdo/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,7 @@ public function find($arg = null)
// Numerically indexed arrays are assumed to be an array of
// primary keys.
$query = new Horde_Rdo_Query();
$query->combineWith('OR');
foreach ($argv[0] as $id) {
$query->addTest($this->primaryKey, '=', $id);
}
$query->addTest($this->primaryKey, 'IN', $arg);
} else {
$query = $arg;
}
Expand Down
6 changes: 3 additions & 3 deletions src/DefaultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct($rdo)
/**
* Reset to the first key.
*/
public function rewind()
public function rewind(): void
{
$this->_valid = (false !== reset($this->_keys));
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public function key()
/**
* Move to the next key in the iterator.
*/
public function next()
public function next(): void
{
$this->_valid = (false !== next($this->_keys));
}
Expand All @@ -99,7 +99,7 @@ public function next()
*
* @return boolean Inside array bounds?
*/
public function valid()
public function valid(): bool
{
return $this->_valid;
}
Expand Down
16 changes: 8 additions & 8 deletions src/DefaultList.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __destruct()
/**
* Implementation of the rewind() method for iterator.
*/
public function rewind()
public function rewind(): void
{
if ($this->_result) {
unset($this->_result);
Expand Down Expand Up @@ -168,7 +168,7 @@ public function key()
* @return Base|null The next Rdo object in the set or
* null if no more results.
*/
public function next()
public function next(): void
{
if (is_null($this->_result)) {
$this->rewind();
Expand All @@ -191,7 +191,7 @@ public function next()
}
}

return $this->_current;
// return $this->_current;
}

/**
Expand All @@ -201,7 +201,7 @@ public function next()
*
* @return boolean Whether or not an offset exists.
*/
public function offsetExists($offset)
public function offsetExists($offset): bool
{
$query = BaseQuery::create($this->_query);
$query->limit(1, $offset);
Expand Down Expand Up @@ -233,7 +233,7 @@ public function offsetGet($offset)
*
* @return Base An entity object at the offset position or null
*/
public function offsetSet($offset, $item)
public function offsetSet($offset, $item): void
{
throw new RdoException('You cannot add objects to a result set');
}
Expand All @@ -248,7 +248,7 @@ public function offsetSet($offset, $item)
*
* @return Base An entity object at the offset position or null
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
throw new RdoException('You cannot remove objects from a result set');
}
Expand All @@ -258,7 +258,7 @@ public function offsetUnset($offset)
*
* @return boolean Whether the iteration is valid
*/
public function valid()
public function valid(): bool
{
if (is_null($this->_result)) {
$this->rewind();
Expand All @@ -271,7 +271,7 @@ public function valid()
*
* @return integer Number of elements in the list
*/
public function count()
public function count(): int
{
if (is_null($this->_count)) {
$this->_count = $this->_mapper->count($this->_query);
Expand Down
2 changes: 1 addition & 1 deletion src/RampageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public function hasRelation($relationship, Rampage $peer = null)
* @return integer The number of relations affected
ralflang marked this conversation as resolved.
Show resolved Hide resolved
* @throws RdoException
*/
public function removeRelation(string $relationship, Rampage $peer = null): integer
public function removeRelation(string $relationship, Rampage $peer = null): int
{
return $this->mapper->removeRelation($relationship, $this, $peer);
}
Expand Down
Loading