Skip to content

Commit ff156d8

Browse files
committed
fix: Changed static function invocation
1 parent f4a445e commit ff156d8

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

src/Core/Asset_Loader.php

+38-40
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010

1111
/**
1212
* Asset loader.
13-
*
14-
* @method static self add_bundle( XWP_Asset_Bundle $bundle ) Add a bundle.
15-
* @method static self load_bundle( XWP_Asset_Bundle|array $bundle ) Load a bundle.
16-
* @method static XWP_Asset_Bundle make_bundle( array $args ) Create a bundle.
17-
* @method static ?XWP_Asset_Bundle get_bundle(string $id) Get a bundle by ID.
1813
*/
1914
final class XWP_Asset_Loader {
2015
use Singleton;
@@ -27,20 +22,47 @@ final class XWP_Asset_Loader {
2722
private array $bundles = array();
2823

2924
/**
30-
* Call a static method on the instance.
25+
* Load a bundle.
3126
*
32-
* @param string $name The name of the method to call.
33-
* @param array<mixed> $args The arguments to pass to the method.
34-
* @return mixed
27+
* @param XWP_Asset_Bundle $bundle The bundle to load.
28+
* @return self
29+
*/
30+
public static function add_bundle( XWP_Asset_Bundle $bundle ): self {
31+
return self::instance()->add( $bundle );
32+
}
33+
34+
/**
35+
* Load a bundle, or create a bundle from arguments and load it.
3536
*
36-
* @throws \BadMethodCallException If the method does not exist.
37+
* @param array<string,mixed>|XWP_Asset_Bundle $bundle Bundle instance or bundle arguments.
38+
* @return self
3739
*/
38-
public static function __callStatic( string $name, array $args = array() ): mixed {
39-
if ( ! method_exists( self::class, "call_$name" ) ) {
40-
throw new \BadMethodCallException( esc_html( "Method $name does not exist" ) );
40+
public static function load_bundle( array|XWP_Asset_Bundle $bundle ): self {
41+
if ( ! ( $bundle instanceof XWP_Asset_Bundle ) ) {
42+
$bundle = self::make_bundle( $bundle );
4143
}
4244

43-
return self::instance()->{"call_$name"}( ...$args );
45+
return self::add_bundle( $bundle );
46+
}
47+
48+
/**
49+
* Make a bundle from arguments.
50+
*
51+
* @param array<string,mixed> $args Bundle arguments.
52+
* @return XWP_Asset_Bundle
53+
*/
54+
public static function make_bundle( array $args ): XWP_Asset_Bundle {
55+
return new XWP_Asset_Bundle( ...$args );
56+
}
57+
58+
/**
59+
* Get a bundle by ID.
60+
*
61+
* @param string $id Bundle ID.
62+
* @return XWP_Asset_Bundle|null
63+
*/
64+
public static function get_bundle( string $id ): ?XWP_Asset_Bundle {
65+
return self::instance()->get( $id );
4466
}
4567

4668
/**
@@ -107,43 +129,19 @@ static function () use ( $bundle, $context ) {
107129
* @param XWP_Asset_Bundle $bundle The bundle to load.
108130
* @return self
109131
*/
110-
private function call_add_bundle( XWP_Asset_Bundle $bundle ): self {
132+
private function add( XWP_Asset_Bundle $bundle ): self {
111133
$this->bundles[ $bundle->id() ] = $bundle;
112134

113135
return $this;
114136
}
115137

116-
/**
117-
* Load a bundle, or create a bundle from arguments and load it.
118-
*
119-
* @param array<string,mixed>|XWP_Asset_Bundle $bundle Bundle instance or bundle arguments.
120-
* @return self
121-
*/
122-
private function call_load_bundle( array|XWP_Asset_Bundle $bundle ): self {
123-
if ( ! ( $bundle instanceof XWP_Asset_Bundle ) ) {
124-
$bundle = self::make_bundle( $bundle );
125-
}
126-
127-
return self::add_bundle( $bundle );
128-
}
129-
130-
/**
131-
* Make a bundle from arguments.
132-
*
133-
* @param array<string,mixed> $args Bundle arguments.
134-
* @return XWP_Asset_Bundle
135-
*/
136-
private function call_make_bundle( array $args ): XWP_Asset_Bundle {
137-
return new XWP_Asset_Bundle( ...$args );
138-
}
139-
140138
/**
141139
* Get a bundle by ID.
142140
*
143141
* @param string $id Bundle ID.
144142
* @return XWP_Asset_Bundle|null
145143
*/
146-
private function call_get_bundle( string $id ): ?XWP_Asset_Bundle {
144+
private function get( string $id ): ?XWP_Asset_Bundle {
147145
return $this->bundles[ $id ] ?? null;
148146
}
149147
}

0 commit comments

Comments
 (0)