WpBridge::__call()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
namespace Gwa\Wordpress\WpBridge;
3
4
use Gwa\Wordpress\WpBridge\Contracts\WpBridgeInterface;
5
6
/**
7
 * Allows us to use a class to call methods in the global namespace.
8
 * Methods should be called in camelcase.
9
 *
10
 * To call
11
 * wp_get_attachment_image_src(...);
12
 * use
13
 * $bridge->wpGetAttachmentImageSrc(...);
14
 */
15
class WpBridge implements WpBridgeInterface
16
{
17
    /**
18
     * Magic call on all camel wordpress functions.
19
     *
20
     * @param string $function
21
     * @param array  $args
22
     *
23
     * @return mixed
24
     */
25
    public function __call($function, $args)
26
    {
27
        return call_user_func_array($this->camelToUnderscore($function), $args);
28
    }
29
30
    /**
31
     * Rename camelcase to underscore.
32
     *
33
     * @param string $string
34
     *
35
     * @return string
36
     */
37
    public function camelToUnderscore($string)
38
    {
39
        return strtolower(preg_replace('/([a-z])([A-Z0-9])/', '$1_$2', $string));
40
    }
41
}
42