Skip to content

Commit 4c05c26

Browse files
committed
refactor: switch more to static
1 parent 3bed92a commit 4c05c26

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Models/Contracts/Model.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function getOriginal( string $key = null );
6161
/**
6262
* Determines if the model has the given property.
6363
*
64+
* @since 2.0.0 changed to static
6465
* @since 1.0.0
6566
*
6667
* @param string $key Property name.
@@ -94,6 +95,7 @@ public function isDirty( string $attribute = null ) : bool;
9495
/**
9596
* Validates an attribute to a PHP type.
9697
*
98+
* @since 2.0.0 changed to static
9799
* @since 1.0.0
98100
*
99101
* @param string $key Attribute name.
@@ -106,6 +108,7 @@ public static function isPropertyTypeValid( string $key, $value ) : bool;
106108
/**
107109
* Returns the property keys.
108110
*
111+
* @since 2.0.0 changed to static
109112
* @since 1.0.0
110113
*
111114
* @return int[]|string[]

src/Models/Model.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function fill( array $attributes ) : ModelInterface {
8787
* @throws RuntimeException
8888
*/
8989
public function getAttribute( string $key, $default = null ) {
90-
$this->validatePropertyExists( $key );
90+
static::validatePropertyExists( $key );
9191

9292
return $this->attributes[ $key ] ?? $default;
9393
}
@@ -139,6 +139,7 @@ public function isSet( string $key ): bool {
139139
/**
140140
* Check if there is a default value for a property.
141141
*
142+
* @since 2.0.0 changed to static
142143
* @since 1.2.2
143144
*
144145
* @param string $key Property name.
@@ -152,6 +153,7 @@ protected static function hasDefault( string $key ): bool {
152153
/**
153154
* Returns the default value for a property if one is provided, otherwise null.
154155
*
156+
* @since 2.0.0 changed to static
155157
* @since 1.0.0
156158
*
157159
* @param string $key Property name.
@@ -169,6 +171,7 @@ protected static function getPropertyDefault( string $key ) {
169171
/**
170172
* Returns the defaults for all the properties. If a default is omitted it defaults to null.
171173
*
174+
* @since 2.0.0 changed to static
172175
* @since 1.0.0
173176
*
174177
* @return array<string,mixed>
@@ -262,6 +265,7 @@ protected function hasCachedRelationship( string $key ) : bool {
262265
/**
263266
* Determines if the model has the given property.
264267
*
268+
* @since 2.0.0 changed to static
265269
* @since 1.0.0
266270
*
267271
* @param string $key Property name.
@@ -305,6 +309,7 @@ public function isDirty( string $attribute = null ) : bool {
305309
/**
306310
* Validates an attribute to a PHP type.
307311
*
312+
* @since 2.0.0
308313
* @since 1.0.0
309314
*
310315
* @param string $key Property name.
@@ -428,14 +433,15 @@ public function toArray() : array {
428433
/**
429434
* Validates that the given property exists
430435
*
436+
* @since 2.0.0 changed to static
431437
* @since 1.0.0
432438
*
433439
* @param string $key Property name.
434440
*
435441
* @return void
436442
*/
437-
protected function validatePropertyExists( string $key ) {
438-
if ( ! $this->hasProperty( $key ) ) {
443+
protected static function validatePropertyExists( string $key ) {
444+
if ( ! static::hasProperty( $key ) ) {
439445
$exception = Config::getInvalidArgumentException();
440446
throw new $exception( "Invalid property. '$key' does not exist." );
441447
}
@@ -444,6 +450,7 @@ protected function validatePropertyExists( string $key ) {
444450
/**
445451
* Validates that the given value is a valid type for the given property.
446452
*
453+
* @since 2.0.0 changed to static
447454
* @since 1.0.0
448455
*
449456
* @param string $key Property name.

0 commit comments

Comments
 (0)