Skip to content

Commit 6541267

Browse files
committed
chore: adds additional docs
1 parent b8e8831 commit 6541267

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/Models/Config.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,16 @@ public static function setInvalidArgumentException( string $class ) {
104104
static::$invalidArgumentException = $class;
105105
}
106106

107-
public static function throwInvalidArgumentException( string $message ) {
107+
/**
108+
* Convenience method for throwing the InvalidArgumentException.
109+
*
110+
* @since 2.0.0
111+
*
112+
* @param string $message
113+
*
114+
* @return void
115+
*/
116+
public static function throwInvalidArgumentException( string $message ): void {
108117
throw new static::$invalidArgumentException( $message );
109118
}
110119
}

src/Models/Model.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ public function __construct( array $attributes = [] ) {
6868
* @since 2.0.0 changed to static
6969
*
7070
* @param string $type
71-
* @param mixed $value
71+
* @param mixed $value The query data value to cast, probably a string.
72+
* @param string $property The property being casted.
7273
*
7374
* @return mixed
7475
*/
75-
protected static function castValueForProperty( string $type, $value ) {
76+
protected static function castValueForProperty( string $type, $value, string $property ) {
7677
switch ( $type ) {
7778
case 'int':
7879
return (int) $value;
@@ -390,7 +391,7 @@ public function jsonSerialize() {
390391
* Constructs a model instance from database query data.
391392
*
392393
* @param object|array $queryData
393-
* @param int $mode The level of strictness to take when constructing the object
394+
* @param int $mode The level of strictness to take when constructing the object, by default it will ignore extra keys but error on missing keys.
394395
* @return static
395396
*/
396397
public static function fromQueryData($queryData, $mode = self::BUILD_MODE_IGNORE_EXTRA): static {
@@ -423,7 +424,7 @@ public static function fromQueryData($queryData, $mode = self::BUILD_MODE_IGNORE
423424
}
424425

425426
// Remember not to use $type, as it may be an array that includes the default value. Safer to use getPropertyType().
426-
$instance->setAttribute($key, static::castValueForProperty(static::getPropertyType($key), $queryData[$key]));
427+
$instance->setAttribute($key, static::castValueForProperty(static::getPropertyType($key), $queryData[$key], $key));
427428
}
428429

429430
return $instance;

0 commit comments

Comments
 (0)